CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Add or subtract two variables in TUI (https://www.cfd-online.com/Forums/fluent-udf/194460-add-subtract-two-variables-tui.html)

Tarantino October 16, 2017 09:30

Add or subtract two variables in TUI
 
Hello all

I want to do a simple math in TUI as the following:

Code:

(define a pick-a-real "report surface-integrals volume-flow-rate bc1 ,,")
(define b pick-a-real "report surface-integrals volume-flow-rate bc2 ,,")

(- a b)


and I got this error:

Error: - (subtract): invalid argument [1]: wrong type [not a number]
Error Object: #[compound-procedure]



I tried also:

Code:

(rpsetvar 'x (pick-a-real "report surface-integrals volume-flow-rate bc1 ,,"))
(rpsetvar 'y (pick-a-real "report surface-integrals volume-flow-rate bc2 ,,"))

(- x y)


and I got this error:

Error: eval: unbound variable
Error Object: x


Anyone know what is the problem and how can I fix it?
Thanks.

AlexanderZ October 16, 2017 20:26

Hello,
you may try this approach
Code:

(define (make-new-rpvar name default type)
        (if (not (rp-var-object name))
        (rp-var-define name default type #f)))  ; function for creation new variables
(make-new-rpvar 'x 0.0 'real) ;define new variable x
(rpsetvar 'x (pick-a-real "report surface-integrals volume-flow-rate p ,,")) ; set x value
(rpgetvar 'x) ; get x value

Hope it works.

Best regards

Tarantino October 16, 2017 22:20

Quote:

Originally Posted by AlexanderZ (Post 668139)
Hello,
you may try this approach
Code:

(define (make-new-rpvar name default type)
        (if (not (rp-var-object name))
        (rp-var-define name default type #f)))  ; function for creation new variables
(make-new-rpvar 'x 0.0 'real) ;define new variable x
(rpsetvar 'x (pick-a-real "report surface-integrals volume-flow-rate p ,,")) ; set x value
(rpgetvar 'x) ; get x value

Hope it works.

Best regards


Hi, thanks for your reply.
I think you misunderstood my question.
I successfully define the variables, but cannot do the math on those variables!
You explain how ca I define variable "x" and assign the volume flow rate of a BC to it. There is no problem in this section.
However, how to add a number to "x" for instance. Why
(+ x 2) won't work!

AlexanderZ October 17, 2017 00:36

Quote:

Originally Posted by Tarantino (Post 668144)
Hi, thanks for your reply.
I think you misunderstood my question.
I successfully define the variables, but cannot do the math on those variables!
You explain how ca I define variable "x" and assign the volume flow rate of a BC to it. There is no problem in this section.
However, how to add a number to "x" for instance. Why
(+ x 2) won't work!

If you want for instance x+2 you may use this expression

Code:

(rpsetvar 'x (+ (rpgetvar 'x) 2))
(rpgetvar 'x)

you will see x+2 in console output.

Best regards

Tarantino October 17, 2017 12:36

Quote:

Originally Posted by AlexanderZ (Post 668150)
If you want for instance x+2 you may use this expression

Code:

(rpsetvar 'x (+ (rpgetvar 'x) 2))
(rpgetvar 'x)

you will see x+2 in console output.

Best regards

This works fine.
Thank you so much.


All times are GMT -4. The time now is 12:08.