Access surface averages from a UDF
A user wants to access surface average values in a UDF. This is difficult, but not impossible. The surface averages will have to be calculated on the cortex side of FLUENT. For this use the following: 1.: Load the scheme file from the second Resolution of this Solution into your FLUENT session. 2.: After that, you can access surface averages etc. by the new scheme functions (get-average ids of) and (get-mass-average ids of) (get-minimum ids of) (get-maximum ids of) (get-mass-flow-rate ids) In these, "ids" is a scheme list of surface id's, "of" is a name of a quantity to be averaged etc. on the surface(s). NOTE: These functions may fail for quantities that are not available on face zones! (Help with this is possible.) 3.: Define one or more rp variables: (rp-var-define 'my-var 0. 'real #f) 4.: In a Command Monitor (Solve---Execute-Commands) do something like the following: /report/surface-average 1 2 () velocity-magnitude This will update some buffer in FLUENT, which is necessary so that the following step will return a correct result: 5.: In a second Command Monitor (Solve---Execute-Commands) do something like the following: (rpsetvar 'my-var (get-average '(1 2) 'velocity-magnitude) 6.: In a third command monitor, you can now call an on-demand UDF (using the appropriate TUI command /define/user/exec-on-demand); in the source code of that UDF, you may use `RP_Get_Real("my-var")´ to access the calculated value. NOTE: This will probably (?) not work in parallel FLUENT sessions!! ;;; ;;; SCHEME routine to store the ;;; surface-average for one or more surfaces ;;; in a SCHEME variable ;;; ;;; --- Offers also calculation of min and max values -- see below. ;;; ;;; usage: (load "surface-average.scm") ;;; (define result-variable (get-average '(surface-ids) 'quantity)) ;;; ;;; e.g. (define result (get-average '(3 4) 'velocity-magnitude)) ;;; stores the average velocity mag. of surfaces 3 and 4 in variable "result" ;;; ;;; BE CAREFUL: Use the SURFACE IDs, NOT the ZONE IDS! ;;; To get surface IDs, enter in the TUI: surface/list-surface ;;; ;;; NNOOTTEE: If this is called immediately after the solver has changed ;;; ~~~~~~~~~ the current data, this is not reflected in the values ;;; provided by this routine. To update postprocessing data, ;;; call the corresponding TUI command that calculates the ;;; needed value (but doesn't save it in a scheme variable..)! ;;; (DEFINE (get-average ids of) (map surface? ids) (client-set-node-values #f) (client-fill-node-values of) (surface-average ids) ) (DEFInE (get-mass-average ids of) (map surface? ids) (client-set-node-values #f) (client-fill-node-values of) (surface-mass-average ids #f) ) (DEFINE (get-minimum ids of) (map surface? ids) (client-set-node-values #f) (client-fill-node-values of) (car (cx-surface-get-min-max ids #t)) ) (DEFINE (get-maximum ids of) (map surface? ids) (client-set-node-values #f) (client-fill-node-values of) (cadr (cx-surface-get-min-max ids #t)) ) (DEFINE (get-mass-flow-rate ids) (map surface? ids) (surface-mass-flow-rate ids) ) |
||
![]()
|