FLUENT V6 - Custom GUI Panel to perform parametric post-processing study

Need a nice(r) gui to run parametric post-processing of sets of data files.
A scheme file has been written to do this.

1. Save the Resolution as "para.scm"
2. Start fluent and load your mesh (or case).
3. Load the scheme file using the SCHEME command (load "para.scm") Don't forget to type the parentheses!
4. Open the new panel Parametric->Post-Processing...
5. Set the start number
6. Set the end number
7. Set the increment counter
8. Set the filenname (append .gz) if you want to read zipped files.
9. Enter the file containing the scheme commands to perform your task (on each data file).
10. Click "Apply" to save the settings to the case file. You may wish to re-save the case before you continue.
11. Click "Run" to perform the parametric run.

Start = 0, End =100, Increment = 4, Name = foo-.gz, Journal = graphics.scm

This will load the data files (you must make sure they exist!):


and it will automatically run the scheme commands in "graphics.scm" for each data file.
; GUI definition for Parametric Post-processing
; Function to create rpvars for udf, assign initial (ie: default) values
(define myvars)
(set! myvars '())
(define (new-var name default type) (if (not (rp-var-object name))
(rp-var-define name default type #f)
(set! myvars (list-add myvars name))

;; Function to pad a string with zeros to pad-length
(define (pad-zeros name pad-length)
(if (< (string-length name) pad-length)
(begin (pad-zeros (string-append "0" name) pad-length)) name

(define (auto-run base zipped first last inc journal-file-name )
(if (<= first last)
(define name (string-append base (pad-zeros (number->string first) 4)))
(set! name (string-append name (if zipped ".dat.gz" ".dat")))
(format "Filename = ~a Journal File = ~an" name journal-file-name)
(read-data name)
(load journal-file-name)
(auto-run base zipped (+ first inc) last inc journal-file-name)
(display "nDone with Auto-run study.nn")

; Function to print all user-created rpvars
(define rpr (lambda ()
(if (not (null? myvars))
(let* ((names (map symbol->string myvars))
(values (map rpgetvar myvars))
(f (string-append "~" (number->string (apply max (map string-length names))) "@a = ~an")))
(for-each (lambda (n val) (format f n val)) names values )))))

; Function to add menu item if it does not exist, or delete and re-add if it does exist
(define cx-add-new-item
(lambda (menu item accel mnemonic test callback)
(let ((i (cx-get-item-id menu item)))
(if i (cx-delete-item menu item))
(cx-add-item menu item accel mnemonic test callback)

; Add menu only if it doesn't already exist
(define cx-add-new-menu (lambda (m n) (let ((i (cx-get-menu-id m))) (if (not i) (cx-add-menu m n)))))

; New rpvars
(new-var 'ppp/on? #f 'boolean)
(new-var 'ppp/start 0 'integer)
(new-var 'ppp/end 0 'integer)
(new-var 'ppp/inc 0 'integer)
(new-var 'ppp/filename "" 'string)
(new-var 'ppp/basename "" 'string)
(new-var 'ppp/jouname "" 'string)
(new-var 'ppp/zipped? #f 'boolean)

; Custom units (only works for Fluent 6.2 and higher!)
(define (set-new-units)
(let ((new-unit-conv '())
(set! new-unit-table (map (lambda (x) (cons (car x) (cadr x))) new-unit-conv))
(set! *cx-conversion-table* (append *cx-conversion-table* new-unit-conv))
(set! *cx-unit-table* (append *cx-unit-table* new-unit-table))))
(if (not (symbol-bound? 'units-set? (the-environment))) (set-new-units)) ;; Load only once per session!
(define units-set?)

;; Function that defines the DPF Panel
(define pa-gui-panel
(let ((panel #f)

;;; Function which is called when panel is opened
;;; sets panel variables to values in new-var section
;;; default: all options off, no surfaces selected
(define (update-cb . args)
(cx-set-integer-entry ppp/start-cb (rpgetvar 'ppp/start))
(cx-set-integer-entry ppp/end-cb (rpgetvar 'ppp/end))
(cx-set-integer-entry ppp/inc-cb (rpgetvar 'ppp/inc))
(cx-set-text-entry ppp/filename-cb (rpgetvar 'ppp/filename))
(cx-set-text-entry ppp/jouname-cb (rpgetvar 'ppp/jouname))

(define (apply-settings . args)
(let ((x) (l))
(set! x (cx-show-text-entry ppp/filename-cb))
(rpsetvar 'ppp/jouname (cx-show-text-entry ppp/jouname-cb))
(rpsetvar 'ppp/start (cx-show-integer-entry ppp/start-cb))
(rpsetvar 'ppp/end (cx-show-integer-entry ppp/end-cb))
(rpsetvar 'ppp/inc (cx-show-integer-entry ppp/inc-cb))
(rpsetvar 'ppp/filename x)
(set! l (string-length x))
(if (> l 0)
(if (string=? ".gz" (substring x (- l 3) l ))
(begin (rpsetvar 'ppp/zipped? #t) (rpsetvar 'ppp/basename (substring x 0 (- l 3))))
(begin (rpsetvar 'ppp/zipped? #f) (rpsetvar 'ppp/basename x))

;;; Function which is called when OK button is hit.
;;; assigns variable values that were set in panel after clicking "ok"
(define (run-cb . args)
(if (not (or (= (rpgetvar 'ppp/inc) 0)
(string=? (rpgetvar 'ppp/basename) "")
(string=? (rpgetvar 'ppp/jouname) "")))
(format "Starting Parametric Post-Processing Analysis...nn")
(auto-run (rpgetvar 'ppp/basename)
(rpgetvar 'ppp/zipped?)
(rpgetvar 'ppp/start)
(rpgetvar 'ppp/end)
(rpgetvar 'ppp/inc)
(rpgetvar 'ppp/jouname)

(define (close-cb . args)

(define (set-start-cb . args)
(rpsetvar 'ppp/start (cx-show-integer-entry ppp/start-cb))
(if (> (cx-show-integer-entry ppp/start-cb) (cx-show-integer-entry ppp/end-cb))
(cx-set-integer-entry ppp/end-cb (cx-show-integer-entry ppp/start-cb)))

(define (set-end-cb . args)
(if (> (cx-show-integer-entry ppp/start-cb) (cx-show-integer-entry ppp/end-cb))
(cx-set-integer-entry ppp/start-cb (cx-show-integer-entry ppp/end-cb)))

(define (set-inc-cb . args)
(if (> (cx-show-integer-entry ppp/inc-cb) (- (cx-show-integer-entry ppp/end-cb) (cx-show-integer-entry ppp/start-cb)))
(cx-set-integer-entry ppp/inc-cb (- (cx-show-integer-entry ppp/end-cb) (cx-show-integer-entry ppp/start-cb))))

;;; if panel does not exist, make panel
(lambda args
(if (not panel)
(let ((table))
(set! panel (cx-create-panel "Parametric Post-Processing Settings..."
'apply-callback run-cb
'update-callback update-cb
'close-callback close-cb))
(cx-add-panel-button panel "Apply" apply-settings)
(cx-set-panel-button-label panel "OK" "Run")
;; create table w/o title in panel to enable row by column format
(set! table (cx-create-table panel "" 'border #f 'below 0 'right-of 0))
;;; Create inputs.
(set! box1 (cx-create-table table "" 'row 0 'col 0))
(set! box2 (cx-create-table table "" 'row 1 'col 0))
(set! ppp/start-cb (cx-create-integer-entry box1 "Start" 'width 5 'row 0 'col 0 'minimum 0 'activate-callback set-start-cb))
(set! ppp/end-cb (cx-create-integer-entry box1 "End" 'width 5 'row 0 'col 1 'minimum 0 'activate-callback set-end-cb))
(set! ppp/inc-cb (cx-create-integer-entry box1 "Increment" 'width 5 'row 0 'col 2 'minimum 0 'activate-callback set-inc-cb))
(set! ppp/filename-cb (cx-create-text-entry box2 "Base Filename" 'row 0 'col 1 'width 32))
(set! ppp/jouname-cb (cx-create-text-entry box2 "Journal Filename" 'row 1 'col 1 'width 32))

;; display panel
(cx-show-panel panel))))

; Add panel item only if in GUI Fluent
(if (cx-gui?)
(cx-add-new-menu "Parametric" #f)
(cx-add-new-item "Parametric" "Post-Processing..." #A #f cx-client? pa-gui-panel)

Show Form
No comments yet. Be the first to add a comment!