Report averages of quantities on (lists) of surfaces in a file versus time in transient runs

Users wanted to be able to record in a file in a spreadsheet format averages of various quantities versus time in transient runs.
They have as input a list of surfaces; on each of these surfaces, they need the area-weighted average or the mass-weighted
average of the quantity they wish; they want to record these averages in a file in a spreadsheet format versus time, i.e., first
column will be time, then a number of columns equal with the number of surfaces will contain the average quantity on
each individual surface.

A second resolution was added to this Solution, to allow reporting Integrals as well.

A third resolution was added to this Solution, to allow reporting accurately mass flow rates, heat transfer rates, or radiation
heat transfer rates (through boundary zones only).
A Scheme function pasted below was written to perform the requirements described above. The usage
of this Scheme function is also described in the commented lines in the beginning of the file.

;;; This Scheme function is computing
;;; the averaged / mass-averaged value
;;; of any quantity on a list of
;;; zones identified through their names
;;; and saves the values in spreadsheet format
;;; in files named as defined by the user
;;;
;;;
;;; Usage

;;; 1) After reading the case and data file, type the
;;; TUI command
;;;
;;; (define pt1 (open-output-file "av1-export.xls"))
;;; (define pt2 (open-output-file "av2-export.xls"))
;;; ... and so on.
;;;
;;; These commands will open the files for output
;;; under ports pt1, pt2, ..
;;;
;;; 2) File>Read>Scheme .. this file (wgen-file.scm)

;;; 3) Set a monitor command in GUI
;;; Solve>Monitor>Command
;;; with the following content
;;;
;;; (write-g-file used-port average-type quantity list-of-zone-names)
;;;
;;; A correct syntax for the list-of-zone-names looks like
;;;
;;; (list 'inlet-1 'outlet-2 'outlet-3)
;;; so for this example the content of the Command Monitor is:
;;;
;;; (write-g-file pt1 "mass-average" 'total-temperature (list 'inlet-1 'outlet-2 'outlet-3))
;;;
;;; or
;;;
;;; (write-g-file pt2 "average" 'temperature (list 'inlet-1))
;;;
;;; the type "average" corresponds to area averaging
;;; the type "mass-average" corresponds to mass averaging

;;; the symbol 'temperature stands for static temperature
;;; the symbol 'total-temperature stands for total temperature
;;; other symbols maybe used after asking for support

;;; the variable pt1 or pt2 indicates in which file should the
;;; averages be recorded

;;; 4) Set the frequency of executions - Every "n" Time steps

;;; 5) Run the transient analysis

;;; 6) Once you want to close these file you must type the TUI command
;;;
;;; (close-output-port pt1)
;;; (close-output-port pt2)


;;;
;;; Do not change below this line without calling for support
;;; ==========================================================
(define (write-g-file uport gtype gquantity list-surface-names)
(let ((tim)(ll)(g-surface-average))
(set! g-surface-average
(lambda (type quantity list-of-surf-names)
(let ((g-surface)(list->strip))
;;;
(set! list->strip
(lambda (inputlist)
(let ((stri "")
(ll (length inputlist)))
(let loop ((i 0))
(if (< i ll)
(begin
(set! stri (string-append stri " " (number->string (list-ref inputlist i))))
(loop (+ i 1))))
stri ))))
;;;
(set! g-surface
(lambda (typx surfx cell-onlyx?)
(if (equal? typx "average")
(surface-average surfx cell-onlyx?)
(surface-mass-average surfx cell-onlyx?))))
;;;;
(let* ((surf-list (map surface-name->id list-of-surf-names))
(input-strip (list->strip surf-list)))
(ti-menu-load-string (string-append "(cxisetvar 'xy/surfaces "") ()"))
(ti-menu-load-string (string-append "(cxisetvar 'xy/surfaces "") " input-strip ","))
(let ((of quantity))
(if of

;;; the next line changed from (cell-only? (cx-cell-only-field? of)) ot (cell-only? (cx-cell-only-field? "mixture" of))
;;; to cope with F6.3 format. mlo

(let ((cell-only? (cx-cell-only-field? "mixture" of))
(surfaces (cxgetvar 'xy/surfaces)))
(client-set-node-values #f)
(client-fill-node-values of)
(cx-fill-face-zone-values surfaces of)
(g-surface type surfaces cell-only?))))))
))
(set! tim (rpgetvar 'flow-time))
(format uport " ~a " tim)
(set! ll (length list-surface-names))
(let loop ((i 0))
(if (< i ll)
(begin
(format uport " t ~a" (g-surface-average gtype gquantity (list (list-ref list-surface-names i))))
(loop (+ i 1)))
(newline uport)
))
))With a change in the body of the Scheme function, this can be used for
computing averages or integrals on surfaces. The function was modified
to accomodate hooking any surface operator inside (see below).
;;;=====================================================;;;
;;; This Scheme function is computing
;;; the averaged / mass-averaged / integral values
;;; of any quantity on a list of
;;; zones identified through their names
;;; and saves the values in spreadsheet format
;;; in files named as defined by the user
;;;
;;;
;;; Usage

;;; 1) After reading the case and data file, type the
;;; TUI command
;;;
;;; (define pt1 (open-output-file "av1-export.xls"))
;;; (define pt2 (open-output-file "av2-export.xls"))
;;; (define pt3 (open-output-file "int3-export.xls"))
;;; ... and so on.
;;;
;;; These commands will open the files for output
;;; under ports pt1, pt2, pt3, ...

;;;
;;; 2) File>Read>Scheme .. this file (wgenop-file.scm)

;;; 3) Set a monitor command in GUI
;;; Solve>Monitor>Command
;;; with the following content
;;;
;;; (write-g-file used-port operator-type quantity list-of-zone-names)
;;;
;;; A correct syntax for the list-of-zone-names looks like
;;;
;;; (list 'inlet-1 'outlet-2 'outlet-3)
;;; so for this example the content of the Command Monitor is:
;;;
;;;
;;; (write-g-file pt1 "mass-average" 'total-temperature (list 'inlet-1 'outlet-2 'outlet-3))
;;;
;;; or
;;;
;;; (write-g-file pt2 "average" 'temperature (list 'inlet-1))
;;;
;;; or
;;;
;;; (write-g-file pt3 "integral" 'pressure (list 'plane-1 'plane-2))
;;;
;;; the operator type "average" corresponds to area averaging
;;; the type "mass-average" corresponds to mass averaging
;;; the type "integral" corresponds to surface integral

;;; the symbol 'temperature stands for static temperature
;;; the symbol 'total-temperature stands for total temperature
;;; other symbols maybe used after asking for support

;;; the variable pt1, pt2, pt3 indicates in which file
;;; averages or surface integrals should be recorded

;;; 4) Set the frequency of executions - Every "n" Time steps

;;; 5) Run the transient analysis

;;; 6) Once you want to close these file you must type the TUI command
;;;
;;; (close-output-port pt1)
;;; (close-output-port pt2)
;;; (close-output-port pt3)
;;; ...
;;;
;;; Do not change below this line without calling for support
;;; ==========================================================
(define (write-g-file uport gtype gquantity list-surface-names)
(let ((tim)(ll)(g-surface-operator))
(set! g-surface-operator
(lambda (type quantity list-of-surf-names)
(let ((g-surface-op)(list->strip))
;;;
(set! list->strip
(lambda (inputlist)
(let ((stri "")
(ll (length inputlist)))
(let loop ((i 0))
(if (< i ll)
(begin
(set! stri (string-append stri " " (number->string (list-ref inputlist i))))
(loop (+ i 1))))
stri ))))
;;;
(set! g-surface-op
(lambda (typx surfx cell-onlyx?)
(cond
((equal? typx "average")
(surface-average surfx cell-onlyx?))
((equal? typx "mass-average")
(surface-mass-average surfx cell-onlyx?))
((equal? typx "integral")
(surface-integral surfx cell-onlyx?))
(else (format "n "~a" is an undefined surface operator n
Only "average" "mass-average" "integral" are available at this time !n"
typx)))
))
;;;;
(let* ((surf-list (map surface-name->id list-of-surf-names))
(input-strip (list->strip surf-list)))
(ti-menu-load-string (string-append "(cxisetvar 'xy/surfaces "") ()"))
(ti-menu-load-string (string-append "(cxisetvar 'xy/surfaces "") " input-strip ","))
(let ((of quantity))
(if of
(let ((cell-only? (cx-cell-only-field? of))
(surfaces (cxgetvar 'xy/surfaces)))
(client-set-node-values #f)
(client-fill-node-values of)
(cx-fill-face-zone-values surfaces of)
(g-surface-op type surfaces cell-only?))))))
))
(set! tim (rpgetvar 'flow-time))
(format uport " ~a " tim)
(set! ll (length list-surface-names))
(let loop ((i 0))
(if (< i ll)
(begin
(format uport " t ~a" (g-surface-operator gtype gquantity (list (list-ref list-surface-names i))))
(loop (+ i 1)))
(newline uport)
))
))The previous two Scheme functions are able to provide averages and integrals of various quantities on any surface (zone or postprocessing
entity only). However, it was noticed that the values for (a) mass flow rates (b) heat transfer rates (c) radiated heat transfer rates reported using these Schemes or GUI / TUI commands going through Report>Surface Integrals are quite different from the real ones reported in Report>Fluxes.

Because of that, if the request is to save (a) mass flow rates (b) heat transfer rates (c) radiation heat transfer rates through boundary zones (and
only for boundary zones !), then the Scheme below should be used instead of the previous two.

;;; This Scheme function is computing
;;; the mass flow, heat transfer, or radiation
;;; heat transfer rates through a list of
;;; boundary zones identified through their names
;;; and saves the values in spreadsheet format
;;; in files named as defined by the user
;;;
;;; Note: When dealing with a multiphase problem,
;;; the results will be valid for the mixture domain.
;;; Usage

;;; 1) After reading the case and data file, type the
;;; TUI command
;;;
;;; (define pt1 (open-output-file "htr-export.xls"))
;;; (define pt2 (open-output-file "mfr-export.xls"))
;;; (define pt3 (open-output-file "rtr-export.xls"))
;;; ... and so on.
;;;
;;; These commands will open the files for output
;;; under ports pt1, pt2, pt3, ...

;;;
;;; 2) File>Read>Scheme .. this file (w-mass-heat-file.scm)

;;; 3) Set a monitor command in GUI
;;; Solve>Monitor>Command
;;; with the following content
;;;
;;; (write-mhr-file used-port quantity list-of-zone-names)
;;;
;;; A correct syntax for the list-of-zone-names looks like
;;;
;;; (list 'inlet-1 'outlet-2 'outlet-3)
;;; so for this example the content of the Command Monitor is:
;;;
;;; (write-mhr-file pt1 'mass-flow (list 'inlet-1 'outlet-2 'outlet-3))
;;;
;;; or
;;;
;;; (write-mhr-file pt2 'heat-transfer (list 'wall-1))
;;;
;;; or
;;;
;;; (write-mhr-file pt3 'rad-heat-transfer (list 'wall-10 'wall-12))
;;;
;;; the symbol 'mass-flow stands for mass flow rate in kg/s
;;; the symbol 'heat-transfer stands for heat transfer rate in W
;;; the symbol 'rad-heat-transfer stands for radiation heat transfer rate in W

;;; the variable pt1, pt2, pt3 indicates in which file
;;; averages or surface integrals should be recorded

;;; 4) Set the frequency of executions - Every "n" Time steps
;;; 5) Run the transient analysis

;;; 6) Once you want to close these file you must type the TUI command
;;;
;;; (close-output-port pt1)
;;; (close-output-port pt2)
;;; (close-output-port pt3)
;;; ...


;;;
;;; Do not change below this line without calling for support
;;; ==========================================================
(define (write-mhr-file uport quantity list-zone-names)
(let ((tim)(ll)(mhr-zone-operator))
(set! mhr-zone-operator
(lambda (xquantity name)
(let* ((id (zone-name->id name))
(fluxes (domain-thread-integrals 1 id)))
(if fluxes
(let ((f (cdr (assq xquantity fluxes))))
f)
0.0))))
(set! tim (rpgetvar 'flow-time))
(format uport " ~a " tim)
(set! ll (length list-zone-names))
(let loop ((i 0))
(if (< i ll)
(begin
(format uport " t ~a" (mhr-zone-operator quantity (list-ref list-zone-names i)))
(loop (+ i 1)))
(newline uport)
))))





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