The text interface of Ansys Fluent executes a Scheme interpreter, which allows you to define your own variables that can be stored in Ansys Fluent and accessed via a UDF. This capability can be very useful, for example, if you want to alter certain parameters in your case, and you do not want to recompile your UDF each time. Suppose you want to apply a UDF to multiple zones in a mesh. You can do this manually by accessing a particular Zone ID in the graphical user interface, hard-coding the integer ID in your UDF, and then recompiling the UDF. This can be a tedious process if you want to apply the UDF to a number of zones. By defining your own Scheme variable, if you want to alter the variable later, then you can do it from the text interface using a Scheme command.
Macros that are used to define and access user-specified Scheme variables from the text
interface are identified by the prefix rp
, (for example,
rp-var-define
). Macros that are used to access user-defined Scheme
variables in an Ansys Fluent solver, are identified by the prefix RP
(for
example, RP_Get_Real
). These macros are executed within UDFs.
For more information, see the following sections:
To define a Scheme variable named
user/pres_av/thread-id
in the text interface, you can use the
following Scheme command:
(rp-var-define ’user/pres_av/thread-id 2 ’integer #f)
This will create the Scheme variable as an integer type and assign it the initial value
2
. Your Scheme variable and its value will be saved and restored
with the case file. Other types besides 'integer
include
'real
, 'boolean
, and
'string
.
Typically, you should avoid redefining an existing Scheme variable. The following Scheme
command will only define a new Scheme variable if there is not an existing Scheme variable
with the same name, therefore it is preferred over the (rp-var-define
'…)
command:
(make-new-rpvar 'user/pres_av/thread-id 2 'integer)
This command first checks that the variable
user/pres_av/thread-id
is not already defined, and then sets it up
as an integer with an initial value of 2
. If a Scheme
variable with this name is already defined, its value will not be changed/overwritten by
this command.
Note that the string ’/’
is allowed in Scheme variable names (as in user/pres_av/thread-id
),
and is a useful way to organize variables so that they do not interfere with each
other.
After you define a Scheme variable in the text interface, you can
access the variable. For example, if you want to check the current value of the variable
(for example, user/pres_av/thread-id
) on the Scheme side, you can
type the following command in the text window:
(%rpgetvar ’user/pres_av/thread-id)
Important: It is recommended that you use %rpgetvar
when you are
retrieving an Ansys Fluent variable using a Scheme command. The %
symbol forces Ansys Fluent to check for the stored value of the variable instead of the
buffered value. Access to buffered values using rpgetvar
(without
the %
symbol) is faster, but when the RP variable is changed from
the C side (a UDF or Ansys Fluent), the buffered value might be outdated. Only in instances
where the variable is not changed from the C side, can you neglect the
%
symbol and use the buffered value with confidence.
Alternatively, if you want to change the value of the variable
you have defined (user/pres_av/thread-id
) to say,
7
, then you will need to use rpsetvar
and
issue the following command in the text window:
(rpsetvar ’user/pres_av/thread-id 7)
After a new variable is defined on the Scheme side (using a text command), you will need
to bring it over to the solver side to be able to use it in your UDF. ‘
RP
’ macros are used to access Scheme variables in UDFs,
and are listed below.
|
Returns true if the variable exists |
|
Returns the double value of |
|
Returns the integer value of |
|
Returns the const char* value of |
|
Returns the Boolean value of |
|
Returns the input parameter value of |
For example, to access the user-defined Scheme variable
user/pres_av/thread-id
in your UDF C function, you will use
RP_Get_Integer
. You can then assign the variable returned to a
local variable you have declared in your UDF (for example,
surface_thread_id
) as demonstrated below:
surface_thread_id = RP_Get_Integer("user/pres_av/thread-id");
You can also change a Scheme variable in your UDF using the following RP macros:
|
Sets the double value of |
|
Sets the integer value of |
|
Sets the const char* value of |
|
Sets the Boolean value of |
Important: When you change the value of a Scheme variable in a UDF using
RP_Set_...
, it must be done on every process (host and nodes)
that will access the value with the RP_Get_...
macro. Ensure that
the value is synchronized between the node(s) and host processes before using
RP_Set_...
.
To enable the consistent use of the changed value on the Scheme side,
RP_Set_...
must be called on the host process and the Scheme
side must use (%rpgetvar '…)
(refer to Accessing a Scheme Variable in the Text Interface for more information).