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/)
-   -   Reading RP Var from the GUI (https://www.cfd-online.com/Forums/fluent-udf/169485-reading-rp-var-gui.html)

Bruno Machado April 11, 2016 11:56

Reading RP Var from the GUI
 
Hello,

I modeled a fuel cell using UDF, but I want read, every time I initialize my model, couple of RP variables.The following line shows one of the variables I defined in the scheme (318.15 is just a initial value).

(make-new-rpvar 'fuel-cell/operating-temp 318.15 'real) ;; K

My problem is that I want to do something like (these 2 lines that follows goes within the DEFINE_INIT)

Message("\n Define the operating temperature: 313.15 - 400 [K]");
XXXXXXXXXXXXX (in this line I need to read a value and set it to the rpvar operating-temp, but I do not know how)

Then, within the code, I could use it as

T0 = RP_Get_Real("fuel-cell/operating-temp");

Does anyone know how to write this line? Fluent documentation regarding the User Define Scheme is very poor, and there is not much information regarding this.

Thanks in advanced.

pakk April 12, 2016 07:39

Read from what? From the solution? From a file? Or do you really mean that you want the user to type the value?

If it is the latter... I see two possible options.
1. Add a dialog box, as explained in the Fluent manual->Customization Manual->II Creating Custom User Interfaces in Fluent->5. Comprehensive examples->5.1 Dialog Box Example, together with 5.3. UDF Example. It is not like you describe, and maybe not what you want, but it might be similar enough. This is in the Help in this location since Fluent 16, but it probably was already working before.

2. Try to use standard c code for reading lines. Such as 'scanf' or 'fgets'. I don't know if they work...

Bruno Machado April 12, 2016 12:29

1 Attachment(s)
Quote:

Originally Posted by pakk (Post 594631)
Read from what? From the solution? From a file? Or do you really mean that you want the user to type the value?

If it is the latter... I see two possible options.
1. Add a dialog box, as explained in the Fluent manual->Customization Manual->II Creating Custom User Interfaces in Fluent->5. Comprehensive examples->5.1 Dialog Box Example, together with 5.3. UDF Example. It is not like you describe, and maybe not what you want, but it might be similar enough. This is in the Help in this location since Fluent 16, but it probably was already working before.

2. Try to use standard c code for reading lines. Such as 'scanf' or 'fgets'. I don't know if they work...

Sorry about that, I forgot to tell that it was reading from the keyboard.

Nevertheless, I took one of your suggestions and created my own (simple but efficient) dialog box. At a first try I thought about using a droplist, but did not work since I need real values instead of strings. As a second option, I changed it to a typing input and produced my code as it follows:

Code:

(define (make-new-rpvar name default type)
 (if (not (rp-var-object name))
 (rp-var-define name default type #f)))

;RP Variable Declarations

(make-new-rpvar 'fuel-cell/operating-temp 313.15 'real)
(make-new-rpvar 'fuel-cell/ref-current-density 10000.0 'real) ;; A/m2
(make-new-rpvar 'fuel-cell/output-voltage 0.6 'real) ;; V
(make-new-rpvar 'fuel-cell/contact-angle 100.0 'real) ;;
(make-new-rpvar 'fuel-cell/stoich-anode 1.5 'real) ;;
(make-new-rpvar 'fuel-cell/stoich-cathode 2.0 'real) ;;

;Dialog Box Definition
(define gui-dialog-box
 ;Let Statement, Local Variable Declarations
 (let ((dialog-box #f)
 (table)
 (fuel-cell/operating-temp)
 (fuel-cell/ref-current-density)
 (fuel-cell/output-voltage)
 (fuel-cell/contact-angle)
 (fuel-cell/stoich-anode)
 (fuel-cell/stoich-cathode)
 )

 ;Update-CB Function, Invoked When Dialog Box Is Opened
 (define (update-cb . args)
 (cx-set-real-entry fuel-cell/operating-temp (rpgetvar 'fuel-cell/operating-temp))
 (cx-set-real-entry fuel-cell/ref-current-density (rpgetvar 'fuel-cell/ref-current-density))
 (cx-set-real-entry fuel-cell/output-voltage (rpgetvar 'fuel-cell/output-voltage))
 (cx-set-real-entry fuel-cell/contact-angle (rpgetvar 'fuel-cell/contact-angle))
 (cx-set-real-entry fuel-cell/stoich-anode (rpgetvar 'fuel-cell/stoich-anode))
 (cx-set-real-entry fuel-cell/stoich-cathode (rpgetvar 'fuel-cell/stoich-cathode))
 )

 ;Apply-CB Function, Invoked When "OK" Button Is Clicked
 (define (apply-cb . args)
 (rpsetvar 'fuel-cell//operating-temp (cx-show-real-entry fuel-cell/operating-temp))
 (rpsetvar 'fuel-cell/ref-current-density (cx-show-real-entry fuel-cell/ref-current-density))
 (rpsetvar 'fuel-cell/output-voltage (cx-show-real-entry fuel-cell/output-voltage))
 (rpsetvar 'fuel-cell/contact-angle (cx-show-real-entry fuel-cell/contact-angle))
 (rpsetvar 'fuel-cell/stoich-anode (cx-show-real-entry fuel-cell/stoich-anode))
 (rpsetvar 'fuel-cell/stoich-cathode (cx-show-real-entry fuel-cell/stoich-cathode))
 (%run-udf-apply 2)
 )

 ;Args Function, Used For Interface Setup, Required For Apply-CB, Update-CB, and Button-CB Sections
 (lambda args
 (if (not dialog-box)
 (let ()
 (set! dialog-box (cx-create-panel "AEM Fuel Cell - Operating Parameters" apply-cb update-cb))
 (set! table (cx-create-table dialog-box "" 'border #f 'below 0 'right-of 0))


 (set! fuel-cell/box1 (cx-create-table table "Operating parameters" 'row 0))
 (set! myudf/real (cx-create-real-entry fuel-cell/box1 "Operating temperature: 313.15 - 333.15 [K]" 'row 0))
 (set! myudf/real (cx-create-real-entry fuel-cell/box1 "Reference current density: 10000 - 30000 [A/m3]" 'row 1))
 (set! myudf/real (cx-create-real-entry fuel-cell/box1 "Output voltage: 0.3 - 1.0 [V] " 'row 2))
 (set! myudf/real (cx-create-real-entry fuel-cell/box1 "Contact angle: 100 - 140 [degree]" 'row 3))
 (set! myudf/real (cx-create-real-entry fuel-cell/box1 "Stoichometry ratio at anode: 1.2 - 2.0 [-]" 'row 4))
 (set! myudf/real (cx-create-real-entry fuel-cell/box1 "Stoichometry ratio at cathode: 2.0 - 3.0 [-]" 'row 5))

  ) ;End Of Let Statement
 ) ;End Of If Statement

 ;Call To Open Dialog Box
 (cx-show-panel dialog-box)
 ) ;End Of Args Function
 ) ;End Of Let Statement
) ;End Of GUI-Dialog-Box Definition

(cx-add-menu "Fuel Cell Menu" #f)
(cx-add-hitem "Fuel Cell Menu" "AEM Fuel Cell" #f #f #t #f)
;Menu Item Added To Above Created "New Menu->New Submenu" Submenu In Fluent
(cx-add-item "AEM Fuel Cell" "Operating Parameters" #\U #f #t gui-dialog-box)


pakk April 13, 2016 03:57

Wow. Looks impressive!


All times are GMT -4. The time now is 10:35.