CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   Writing surface report to a file using journal file (https://www.cfd-online.com/Forums/fluent/235459-writing-surface-report-file-using-journal-file.html)

eccc April 15, 2021 11:53

Writing surface report to a file using journal file
 
Hi
I'm currently attempting something that should be relatively straightforward: I want to take an area-weighted average on a surface, and write that value to a file using a journal command. I want to do this from an existing data file, not as I'm running my calculation.

This is easily achievable through the GUI by simply going through the report interface and clicking 'write' after I've calculated my average. However, I can't seem to find an equivalent journal command. (The report/surface-integrals tree doesn't have a write option, and the file tree doesn't seem to have a surface-integrals option)

(The reason I'm doing this is simply that I have a large number of data files that I'd like to loop through and take the report from each of them)

AlexanderZ April 15, 2021 22:33

you don't need journal file to do that
it is possible to write to file integrals vs time:
solution -> report-definition -> new -> surface-report -> area-weight average -> select variable and face -> OK

now create output file:
solution-> monitors -> report Files -> new -> select your variable -> define file name -> OK

eccc April 16, 2021 05:10

Thanks for your response. Unfortunately I'm not sure its applicable to my case, as I already have the solution data files and I don't want to rerun the simulation.
I'm looking instead to write the value from a journal file as I already have a script to loop through the existing data files and perform the journal operations on them. I'd rather not go through each one manually writing out the value.

AlexanderZ April 19, 2021 01:30

to write output at the end of file:
Code:

(ti-menu-load-string (format #f " report surface-integrals area-weighted-avg *surface_name* () *variable* yes *filename.srp*  "))
change *surface_name*, *variable*, *filename.srp* according to your needs, * is not needed

output will look like this
Quote:

"Surface Integral Report"

Area-Weighted Average
Static Temperature (k)
----------------------------------------------------
surface_name 299.99997
or you can get only value:
Code:

(pick-a-real  (format #f "report surface-integrals area-weighted-avg *surface_name* () *variable* no"))
in that case you should organize writing to file using scheme language

Code:

;;;write to file
(define call-with-output-file
          (lambda (filename proc)
                (let ((p (open-output-file filename "a"))) ;;; a means my_append
                  (let ((v (proc p)))
                        (close-output-port p)
                        v)))
)
;;;write to file in format: Filename | Data (as a list)
(define (write_this filename data)
        (call-with-output-file filename
          (lambda (p)
                (let f ((ls data))
                        (if (not (null? ls))
                                (begin
                                        (write (car ls) p)
                                        (write #\tab p)
                                        (f (cdr ls))
                                )
                                (newline p)
                        ))))
)
;;;convert list from pairs
(define (flatten x)
        (cond
                ((null? x) x)
                ((and (pair? x)
                          (not (pair? (car x))))
                (cond
                  ((null? (car x)) (flatten (cdr x)))
                  (else (cons (car x) (flatten (cdr x))))))
                ((and (pair? x)
                          (pair? (car x)))
                (flatten (cons (caar x)
                                                (cons (cdar x) (cdr x)))))
                (else (cons x '())))
)
;;; put face name inside " " | example (get_surface_avg "surface_name")
(define (get_surface_avg surface_name)
        (pick-a-real  (format #f "report surface-integrals area-weighted-avg ~a () *variable* no" surface_name))
)
;;; run this to execute
(write_this "_surface_avg" (flatten (get_surface_avg "surface_name")))

so you will need to put last line (write_this "_surface_avg" (flatten (get_surface_avg "surface_name"))) inside loop over data files

eccc April 19, 2021 07:29

Thanks so much for this - although actually I realise now that the option to write to file was always there under report and I simply wasn't going far enough to find it. Incidentally, I'm having a hard time finding much documentation on the scheme language. Do you have any good source of info on it?

AlexanderZ April 20, 2021 01:07

https://www.researchgate.net/publica..._Dokumentation

there you can find literature list, but in German:
Quote:

Leider gibt es außer diesem Dokument keine Literatur, die speziell auf Fluent-Scheme eingeht. DaScheme eine sehr mächtige Sprache ist, mit der anspruchsvolle Anwendungen wie KünstlicheIntelligenz realisiert werden können, gehen die meisten Scheme-Bücher viel weiter in die Tiefe, alses für Fluent notwendig ist. Ich verwende das Buch:R. Kent Dybvig, The Scheme Programming Language, Second Edition, 1996 Prentice Hall PTR.Online Version: http://www.scheme.com/tspl2d/index.html [http://www.scheme.com/tspl2d/index.html]Fluent empfielt folgende Scheme-Links im Web:http://www.swiss.ai.mit.edu/projects/scheme [http://www.swiss.ai.mit.edu/projects....schemers.org/ [http://www.schemers.org/]Einige Scheme-Beispiele zu FLUENT sind mittlerweile im FLUENT User Service Center im „OnlineTechnical Support“ zu finden:http://www.fluentusers.com/ [http://www.fluentusers.com/]Überblick über Online-Scheme Literatur im Netz:http://library.readscheme.org/page2.html [http://library.readscheme.org/page2.html]
there was english version somewhere, you may try to find it


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