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

Defining a parameter for UDF

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 14, 2011, 11:11
Default Defining a parameter for UDF
  #1
New Member
 
Philipp Schapotschnikow
Join Date: Oct 2010
Posts: 11
Rep Power: 16
Philipp_Sch is on a distinguished road
Hi all,

I have a UDF which requires a constant, real parameter. Is there a way to give this parameter a value, without having to modify and recompile the source?

Thanks,
Philipp
Philipp_Sch is offline   Reply With Quote

Old   April 14, 2011, 16:28
Default
  #2
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 735
Blog Entries: 1
Rep Power: 23
Amir is on a distinguished road
Hi,
refer to:
"Defining a Scheme Variable in the Text Interface" &
"Accessing a Scheme Variable in a UDF"
in UDF manual.
Amir is offline   Reply With Quote

Old   April 15, 2011, 04:56
Default
  #3
New Member
 
Philipp Schapotschnikow
Join Date: Oct 2010
Posts: 11
Rep Power: 16
Philipp_Sch is on a distinguished road
Thanks a lot, Amir!!

Is there a way to check whether a variable (with the given name) has been defined in the TUI? The manual shows how to check this in TUI (which is already quite useful). But I would like to do the same in the UDF, something like

int myVar;
...
if(isDefined("variable-name")
myVar = RP_Get_Integer("variable-name");
else
myVar = DefaultValue;
Philipp_Sch is offline   Reply With Quote

Old   April 15, 2011, 11:55
Default
  #4
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 735
Blog Entries: 1
Rep Power: 23
Amir is on a distinguished road
I'm not sure, but if you check whether the retrieved value in UDF is equal to NULL or not, may help you.
Amir is offline   Reply With Quote

Old   April 15, 2011, 11:59
Default
  #5
New Member
 
Philipp Schapotschnikow
Join Date: Oct 2010
Posts: 11
Rep Power: 16
Philipp_Sch is on a distinguished road
A call RP_Get_Real with an invalid scheme variable name produces a runtime error
Philipp_Sch is offline   Reply With Quote

Old   April 18, 2011, 22:23
Default
  #6
Senior Member
 
Join Date: Feb 2010
Posts: 164
Rep Power: 17
gearboy is on a distinguished road
Quote:
Originally Posted by Philipp_Sch View Post
Thanks a lot, Amir!!

Is there a way to check whether a variable (with the given name) has been defined in the TUI? The manual shows how to check this in TUI (which is already quite useful). But I would like to do the same in the UDF, something like

int myVar;
...
if(isDefined("variable-name")
myVar = RP_Get_Integer("variable-name");
else
myVar = DefaultValue;
You can use "CX_Interpret_String" function to perform scheme command in UDF.
gearboy is offline   Reply With Quote

Old   April 19, 2011, 05:53
Default
  #7
New Member
 
Philipp Schapotschnikow
Join Date: Oct 2010
Posts: 11
Rep Power: 16
Philipp_Sch is on a distinguished road
I use the following construction

int ret=0;
const int default_value;
...
ret = (int) CX_Interpret_String("( (if (rp-var-object 'var-name)) (%rpgetvar 'var-name))");
if(!ret)
ret = default_value;
return ret;

The UDF shows correct behaviour, but it returns error messages
Error : eval : unbound variable
Error object: %rpgetvar

These error messages make the execution extremely slow (but do not terminate it!). How can I avoid it?

I have no idea of scheme programming, can anyone suggest me how to write a line that does

" if variable "var_name" is defined, return 1, else return 0 "
Philipp_Sch is offline   Reply With Quote

Old   April 19, 2011, 22:28
Default
  #8
Senior Member
 
Join Date: Feb 2010
Posts: 164
Rep Power: 17
gearboy is on a distinguished road
Quote:
Originally Posted by Philipp_Sch View Post
I use the following construction

int ret=0;
const int default_value;
...
ret = (int) CX_Interpret_String("( (if (rp-var-object 'var-name)) (%rpgetvar 'var-name))");
if(!ret)
ret = default_value;
return ret;

The UDF shows correct behaviour, but it returns error messages
Error : eval : unbound variable
Error object: %rpgetvar

These error messages make the execution extremely slow (but do not terminate it!). How can I avoid it?

I have no idea of scheme programming, can anyone suggest me how to write a line that does

" if variable "var_name" is defined, return 1, else return 0 "
Just use:
CX_Interpret_String("(if (rp-var-object 'var-name) (rpgetvar 'var-name)(rpsetvar 'var-name default-value))");

ret=RP_Get_Integer("var-name");
gearboy is offline   Reply With Quote

Old   April 20, 2011, 05:35
Default
  #9
New Member
 
Philipp Schapotschnikow
Join Date: Oct 2010
Posts: 11
Rep Power: 16
Philipp_Sch is on a distinguished road
Quote:
Originally Posted by gearboy View Post
Just use:
CX_Interpret_String("(if (rp-var-object 'var-name) (rpgetvar 'var-name)(rpsetvar 'var-name default-value))");

ret=RP_Get_Integer("var-name");
This gives an error message because rpsetvar tries to set an undefined variable.

I also tried
CX_Interpret_String("(if (not (rp-var-object 'var-name))(rp-var-define 'var-name default-value 'integer #f))");
ret=RP_Get_Integer("var-name");

but it gives me an error "var-name" undefined variable.

I should also mention that I am using a compiled UDF.

Can it be that I need to include certain headers that are not present in udf.h?
Philipp_Sch is offline   Reply With Quote

Old   April 27, 2011, 22:19
Default
  #10
Senior Member
 
Join Date: Feb 2010
Posts: 164
Rep Power: 17
gearboy is on a distinguished road
Quote:
Originally Posted by Philipp_Sch View Post
This gives an error message because rpsetvar tries to set an undefined variable.

I also tried
CX_Interpret_String("(if (not (rp-var-object 'var-name))(rp-var-define 'var-name default-value 'integer #f))");
ret=RP_Get_Integer("var-name");

but it gives me an error "var-name" undefined variable.

I should also mention that I am using a compiled UDF.

Can it be that I need to include certain headers that are not present in udf.h?
"default-value " is a representation of the default value of 'var-name, e.g. -1.

CX_Interpret_String("(if (not (rp-var-object 'var-name))(rp-var-define 'var-name -1 'integer #f))");
ret=RP_Get_Integer("var-name");
gearboy is offline   Reply With Quote

Old   May 2, 2011, 12:07
Default
  #11
New Member
 
Philipp Schapotschnikow
Join Date: Oct 2010
Posts: 11
Rep Power: 16
Philipp_Sch is on a distinguished road
Quote:
Originally Posted by gearboy View Post
"default-value " is a representation of the default value of 'var-name, e.g. -1.

CX_Interpret_String("(if (not (rp-var-object 'var-name))(rp-var-define 'var-name -1 'integer #f))");
ret=RP_Get_Integer("var-name");

Yes, that's what I meant. In the actual code, I have something like

CX_Interpret_String("(if (not (rp-var-object 'var-name))(rp-var-define 'var-name -1 'integer #f))");

The error still occurs.
Philipp_Sch is offline   Reply With Quote

Old   May 2, 2011, 23:32
Default
  #12
Senior Member
 
Join Date: Feb 2010
Posts: 164
Rep Power: 17
gearboy is on a distinguished road
Quote:
Originally Posted by Philipp_Sch View Post
Yes, that's what I meant. In the actual code, I have something like

CX_Interpret_String("(if (not (rp-var-object 'var-name))(rp-var-define 'var-name -1 'integer #f))");

The error still occurs.
CX_Interpret_String("(if(not(rp-var-object 'var-name))(rp-var-define 'var-name -1 'integer #f)())");
gearboy is offline   Reply With Quote

Reply


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
Parameter Set Problem /Fluid Flow Paul_Re CFX 0 December 4, 2010 15:01
compile errors of boundary condition "expDirectionMixed" liying02ts OpenFOAM Bugs 2 February 1, 2010 21:11
MAxium residual...confusion with expert parameter KK CFX 3 February 8, 2008 11:47
Expert Parameter for compressible transient ioannis CFX 0 November 2, 2005 20:28
parameter file CMB Siemens 1 December 15, 2003 10:01


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