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

Reading RP Var from the GUI

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

Like Tree2Likes
  • 1 Post By pakk
  • 1 Post By Bruno Machado

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 11, 2016, 12:56
Default Reading RP Var from the GUI
  #1
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 12
Bruno Machado is on a distinguished road
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.
Bruno Machado is offline   Reply With Quote

Old   April 12, 2016, 08:39
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
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 likes this.
pakk is offline   Reply With Quote

Old   April 12, 2016, 13:29
Default
  #3
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 12
Bruno Machado is on a distinguished road
Quote:
Originally Posted by pakk View Post
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)
Attached Images
File Type: png menu fluent.png (49.0 KB, 101 views)
chek321 likes this.
Bruno Machado is offline   Reply With Quote

Old   April 13, 2016, 04:57
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Wow. Looks impressive!
pakk is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Possible Bug in pimpleFoam (or createPatch) (or fluent3DMeshToFoam) cfdonline2mohsen OpenFOAM 3 October 21, 2013 10:28
writing execFlowFunctionObjects immortality OpenFOAM Post-Processing 30 September 15, 2013 07:16
[Commercial meshers] fluentMeshToFoam multidomain mesh conversion problem Attesz OpenFOAM Meshing & Mesh Conversion 12 May 2, 2013 11:52
Problem in running ICEM grid in Openfoam Tarak OpenFOAM 6 September 9, 2011 18:51


All times are GMT -4. The time now is 19:46.