Ansys Polyflow UDFs are written in the language CLIPS. Examples of UDFs can be found in the Ansys Polyflow Examples Manual (which you can find on the Ansys Help site) or in the file
$Polyflow/bin/udf.clp
where $Polyflow
is the environment variable that
indicates where the Ansys Polyflow program has been installed on your computer
system. See the installation instructions for more information.
The CLIPS syntax encapsulates all constructions with parentheses.
An external function is defined by the "deffunction" construct. Besides the
deffunction
keyword, a deffunction construct has three
elements:
a name
a list of parameters (zero or more)
a sequence of actions, or expressions, that will be executed in order when the deffunction is called
The return value of a deffunction is the evaluation of the last action.
A deffunction must have a unique name, different from any CLIPS-reserved keyword
(otherwise, a CLIPS error will be generated). CLIPS variables and positional
parameters start with a ?
sign. The syntax is
case-sensitive.
A deffunction accepts exactly the required number of arguments as defined in Ansys Polydata. For PMAT UDFs, this will be the number of fields defined in Ansys Polydata. For evolution UDFs, there will be one argument.
Here’s an example of the CLIPS syntax. Suppose you want to define a UDF that uses the polynomial function
(32–1) |
The CLIPS equivalent function, here named UDFP1
, with
a descriptive comment, is
; ; This is a polynomial function with 1 argument ; (deffunction UDFP1 (?X1) (+ 4. (* 3. ?X1) (* 2. ?X1 ?X1) (* 1. ?X1 ?X1 ?X1) ))
All expressions are evaluated from left to right, with an order redefined by
parentheses. The value returned (the last action) is the sum of four terms,
three of them being products of the coefficients and the argument named
?X1
.
Lines beginning with ;
are comments, and are ignored
by the interpreter.
To assign a quantity to a variable, CLIPS has the
bind
command. For instance, to assign the variable
X1
the value of 3.
, use
the command
(bind ?X1 3.)
The bind
command can also be used to create new
variables, local to your UDF. For instance, (bind ?MyX (+ 8.
9.))
defines a variable MyX
local to
the UDF, and gives it the value 17.
When a value returned by the function is stored in a bound variable, simply specify the name of that variable as the last executed entry of the function. For example, the earlier polynomial example could be rewritten as
; ; This is a polynomial function with 1 argument ; (deffunction UDFP1 (?X1) (bind ?MyX (+ 4. (* 3. ?X1) (* 2. ?X1 ?X1) (* 1. ?X1 ?X1 ?X1) ) ) ?MyX )
Important: The returned value should not be enclosed by parentheses.