CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

How to create new macro?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 9, 2019, 14:03
Default How to create new macro?
  #1
Member
 
Peter Maroul
Join Date: May 2018
Posts: 52
Rep Power: 8
Pmaroul is on a distinguished road
Hi all.

I saw into the previous forums a fairly strange user defined macro as follows:

int neighborcell(cell_t c, Thread *t, cell_t *cn, Thread **tn, int n).

This macro isn't defined in cell macros in UDF programming. That is probably defined for the first time by a user.

Hereby, One question comes up to me:

How can we define a new macro or function to be inserted in UDF programming?

Thanks in advance for any answer!

P.Maroul
Pmaroul is offline   Reply With Quote

Old   February 11, 2019, 02:29
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
same way as function in C language

best regards
AlexanderZ is offline   Reply With Quote

Old   February 11, 2019, 11:37
Default
  #3
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Quote:
Originally Posted by Pmaroul View Post
Hi all.

I saw into the previous forums a fairly strange user defined macro as follows:

int neighborcell(cell_t c, Thread *t, cell_t *cn, Thread **tn, int n).

This macro isn't defined in cell macros in UDF programming. That is probably defined for the first time by a user.

Hereby, One question comes up to me:

How can we define a new macro or function to be inserted in UDF programming?

Thanks in advance for any answer!

P.Maroul

You gave an example of how to define a function.
And then you ask how to define a function...


You have answered your own question before you asked it!
pakk is offline   Reply With Quote

Old   February 11, 2019, 19:54
Default
  #4
Member
 
Peter Maroul
Join Date: May 2018
Posts: 52
Rep Power: 8
Pmaroul is on a distinguished road
Quote:
Originally Posted by pakk View Post
You gave an example of how to define a function.
And then you ask how to define a function...


You have answered your own question before you asked it!
Thanks Sir.

Ok, but I indicated only a function title . My main question is that where and how to define or recall in macros.

For example, Is it essential to define it in UDF.h or can we define it everywhere in udf macros for example in define-adjust?
Pmaroul is offline   Reply With Quote

Old   February 11, 2019, 20:00
Default
  #5
Member
 
Peter Maroul
Join Date: May 2018
Posts: 52
Rep Power: 8
Pmaroul is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
same way as function in C language

best regards
Thanks a lot.

Therefor, I can define some new functions before UDF macros and then using them in those macros. Isn't it?
Pmaroul is offline   Reply With Quote

Old   February 11, 2019, 22:29
Default
  #6
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
You are making things complicated.
Macros are build in fluent functions, nothing else. You cant modify them (may be can, but not recommended)
On the other hand, you may create file with your own function (or put these functions in your source file for each UDF). When you will compile your UDF hook this file with UDF source. Same as in C

best regards
AlexanderZ is offline   Reply With Quote

Old   February 19, 2019, 06:08
Default
  #7
Member
 
Peter Maroul
Join Date: May 2018
Posts: 52
Rep Power: 8
Pmaroul is on a distinguished road
Dear Alexander


Therefor, Can I write a file (for example file name: udfexample.c) with following structure? Is it correct?

Code:
int neighborcell(cell_t c, Thread *t, cell_t *cn, Thread **tn, int n)
{
.
.
/*  function commands here written*/
.
.
}

/*for example define_init*/

#include "udf.h"
DEFINE_INIT(my_init_func,d)
{
.
.
.
/* text commands here*/
.
.
.
}
Pmaroul is offline   Reply With Quote

Old   February 19, 2019, 06:12
Default
  #8
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
#include "udf.h"
in the first line

you should execute your function from one of Fluent macros. (for example from DEFINE_INIT)

best regards
AlexanderZ is offline   Reply With Quote

Old   February 19, 2019, 06:20
Default
  #9
Member
 
Peter Maroul
Join Date: May 2018
Posts: 52
Rep Power: 8
Pmaroul is on a distinguished road
How is the following one?
Is it true?
Code:

#include "udf.h"
DEFINE_INIT(my_init_func,d)
{/* function definition immediately starts after define init calling*/
int neighborcell(cell_t c, Thread *t, cell_t *cn, Thread **tn, int n)
{
.
.
/*  function commands here written*/
.
.
}/* The end of fuction definition*/

/*First lines of define _init after function definition */
.
.
.
/* text commands here*/
.
.
.
}
Pmaroul is offline   Reply With Quote

Old   February 19, 2019, 22:34
Default
  #10
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
Code:
#include "udf.h"
int neighborcell(cell_t c, Thread *t, cell_t *cn, Thread **tn, int n)
{
.
.
/*  function commands here written*/
.
.
}

/*for example define_init*/

DEFINE_INIT(my_init_func,d)
{
.
.
.
/* text commands here*/
// if you want execute your function:
neighborcell(c, t, cn, tn, n) // of course c , t , cn ,tn, n values should be defined

.
.
.
}
best regards
AlexanderZ is offline   Reply With Quote

Old   February 20, 2019, 06:12
Default
  #11
Member
 
Peter Maroul
Join Date: May 2018
Posts: 52
Rep Power: 8
Pmaroul is on a distinguished road
Dear Alexander

Your Answers was so helpful.
Thanks a lot for your kind attention.

P.Maroul
Pmaroul is offline   Reply With Quote

Reply

Tags
new macro creation


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
OpenFoam "Permission denied" and "command not found" problems. iyidaniel@yahoo.co.uk OpenFOAM Running, Solving & CFD 11 January 2, 2018 07:47
[gmsh] How to create a 3D volume mesh using a existing surface mesh?! RobertHB Mesh Generation & Pre-Processing 0 July 20, 2017 09:12
[ICEM] how to create a 2d tri mesh with quad mesh in the boundary layer seal2013 ANSYS Meshing & Geometry 3 October 6, 2013 17:09
Actuator disk model audrich FLUENT 0 September 21, 2009 08:06
Macro Trouble -Winows Explorer Crashes with Macro Martin Castillo FLUENT 1 July 25, 2007 05:18


All times are GMT -4. The time now is 19:15.