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

Defining a parameter for UDF

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

Reply
 
LinkBack Thread Tools Display Modes
Old   April 14, 2011, 10:11
Default Defining a parameter for UDF
  #1
New Member
 
Philipp Schapotschnikow
Join Date: Oct 2010
Posts: 11
Rep Power: 6
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, 15:28
Default
  #2
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Shiraz, Iran
Posts: 739
Blog Entries: 1
Rep Power: 14
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, 03:56
Default
  #3
New Member
 
Philipp Schapotschnikow
Join Date: Oct 2010
Posts: 11
Rep Power: 6
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, 10:55
Default
  #4
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Shiraz, Iran
Posts: 739
Blog Entries: 1
Rep Power: 14
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, 10:59
Default
  #5
New Member
 
Philipp Schapotschnikow
Join Date: Oct 2010
Posts: 11
Rep Power: 6
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, 21:23
Default
  #6
Senior Member
 
Ji Junjie
Join Date: Feb 2010
Location: Shanghai, China
Posts: 105
Rep Power: 7
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, 04:53
Default
  #7
New Member
 
Philipp Schapotschnikow
Join Date: Oct 2010
Posts: 11
Rep Power: 6
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, 21:28
Default
  #8
Senior Member
 
Ji Junjie
Join Date: Feb 2010
Location: Shanghai, China
Posts: 105
Rep Power: 7
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, 04:35
Default
  #9
New Member
 
Philipp Schapotschnikow
Join Date: Oct 2010
Posts: 11
Rep Power: 6
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, 21:19
Default
  #10
Senior Member
 
Ji Junjie
Join Date: Feb 2010
Location: Shanghai, China
Posts: 105
Rep Power: 7
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, 11:07
Default
  #11
New Member
 
Philipp Schapotschnikow
Join Date: Oct 2010
Posts: 11
Rep Power: 6
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, 22:32
Default
  #12
Senior Member
 
Ji Junjie
Join Date: Feb 2010
Location: Shanghai, China
Posts: 105
Rep Power: 7
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

Thread Tools
Display Modes

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 On
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 CD-adapco 1 December 15, 2003 10:01


All times are GMT -4. The time now is 18:01.