CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   Journal or Scheme to loop through report files (https://www.cfd-online.com/Forums/fluent/223812-journal-scheme-loop-through-report-files.html)

DEd January 27, 2020 17:04

Journal or Scheme to loop through report files
 
Hi, I am trying to create a scheme file that loops through all report-files and changes their filename but I am stuck.

I was trying to first use the command:

Code:

/solve/report-files/list/
and store that in a scheme list. I tried this but

Code:

(define my-monitors-list (ti-menu-load-string "/solve/report-files/list/"))
and then loop through that list to change the filename using

Code:

/solve/report-files/edit/{report-file-name}/file-name
Any help would be appreciated.

vinerm January 28, 2020 08:02

Prefer some other method
 
Hi Daniel

I would recommend using some other method to rename files, such as bash, assuming you are Linux user or PowerShell or Explorer, if you use Windows. Fluent would not be very efficient with that. However, if you still wish to use Fluent, scheme looping is done in the following manner

( do ((n 10 (+ n 10))) ((> n 2000))
(define filen (string-append "basename" (number->string n) ".dat.gz"))
(define expcmd "f rd" filen)
(ti-menu-load-string expcmd)
)

It is a do loop, n being the counter variable with initial value of 10, incremented by 10, and loop runs until n is greater than 2000. You can have nested loops as well.

You may define variables and then the command and finally execute the command. You may use a combination of scheme and Fluent journal commands.

Vinerm

DEd January 28, 2020 09:44

I love to but...
 
I am open to changing these filenames outside fluent but can I?

My use case is the following: I have done a calculation with mesh A and I wish to update the mesh and save the .cas file in the same folder. After reading the mesh i would like to rename all monitors/report-files
Code:

{CASENAME}.flow.out
{CASENAME}.force1.out

or something similar where CASENAME is the new name of the .cas file given after reading the new mesh. Is this possible outside Fluent?

I can't get your example to work. The only thing it outputs is "f rdf rdf rdf rd#f"

I tried changing the code to
Code:

( do ((n 10 (+ n 10))) ((> n 40))
  (define filen (string-append "basename" (number->string n) ".dat.gz"))
  (define expcmd (format "rd ~a\n" filen))
  (ti-menu-load-string expcmd)
)

Which returns

Code:

wd basename10.dat.gz

Error: wta(1st) to lopeninputstring
Error Object: *the-non-printing-object*


vinerm January 28, 2020 09:55

Variables
 
What I shared is a template and not a code to do what you exactly want.

n, basename, .dat.gz, expcmd, filen, etc. are all variables that you have to define. None of these are defined inside Fluent. basename is part of the filenames that is always fixed, e.g., if names are

casefile_001.out
casefile_002.out, and so on, then basename could be casefile_. 001, 002, etc. could be appended via number->string n. And you have to use the journal command that would do what is intended. rd only reads the data file and does nothing. You may have to add multiple lines within the loop that read the outfile and rename those.

Outside Fluent, you may use bash or awk, if you are familiar with those. E.g., in bash, you may do something like

#!/bin/bash

for file in *.out; do
mv "$file" "$(echo $file | sed 's/_//g')";
done

Here file is just a variable whole value is updated within the for loop for each .out file. mv command renames the files. sed replaces _ in the file names with nothing. So, for filenames given earlier, names will change to casefile001.out, casefile002.out.

DEd January 28, 2020 10:11

Yes but..
 
Yes, I agree that you can change the filenames quite easy outside fluent with a bash-script but what if you need to reopen your .cas/.dat file and run the calculation longer?

Then Fluent can't access the same report file that belongs to this .cas/.dat file because the filename stored in the .cas file is NOT what you renamed it outside fluent.

vinerm January 28, 2020 10:32

list-ref could be used
 
You are right, Daniel. In that case, you will have to also update names within Fluent case files, which is cumbersome. So, either you may use map and for-each to go over the list. Another option is to still use do loop and use (list-ref list-name index) to fetch name of the report, save it in a variable, and then modify it. Since list needs to be generated once, it has to be done outside the loop. list-name and index are to be replaced by name of the list, which has to contain names of all the out files. index is a counter, starts with 0 and has to be equal to len(list) - 1. As far as case file name of Fluent case is concerned, that can be fetched using rp variable.

AlexanderZ January 29, 2020 00:23

if you make all settings after loading new mesh you can set all names again using TUI and save case/data as well

vinerm January 30, 2020 04:47

Solved?
 
Daniel, have you finally been able to get Fluent to do what you wanted?

DEd January 30, 2020 04:53

Still can't create list of report-files
 
This is what I got so far. Works but still no success with automatically creating a list of the files (I have to hard code the "'(p1-rfile mflow-rfile)" part instead of retrieving it using "/solve/report-files/list/"). Without that part it will be to cumbersome to use.

Code:

(define (rename_files)
        (define casename (strip-directory (in-package cl-file-package rc-filename)))
        (for-each
                (lambda (name)
                        (define new_filename (format #f "./~a.~a.out" casename name))
                        (ti-menu-load-string (format #f "solve report-files edit ~a filename ~s" name new_filename))
                )
                '(p1-rfile mflow-rfile)
        )       
)


vinerm January 30, 2020 05:02

Solution
 
Daniel, there is a solution to that. There is a very powerful set of commands within Fluent. Just type (pick-docu) in the console and read the details. Essentially, to extract the outcome of a tui command and save it as a scheme variable, you need to pick the outcome. And this command will shows documentation for pick. I hope this will resolve the issue.

Hint: pick has to be used to fetch the output of solve report-files list command to create a list.

DEd January 30, 2020 07:25

vinerm, thanks a lot. That did the trick.

Code:

;; Renames all report files to {CASENAME}.{Report file name}.out  i.e  instead of mflow.out --> Case1.mflow.out
(define (rename_files)
  (define casename (strip-directory (in-package cl-file-package rc-filename)))
  (do ((x 1 (+ x 1))) ((> x 10))
      (define list_item (pick "solve report-files list " x))
      (if (equal? list_item "list")
        (begin
            (define x 100)  ;; break loop
        )
        (begin
            (format "Changing filename of report file ~s\n" list_item)
            (define new_filename (format #f "./~a.~a.out" casename list_item))
            (ti-menu-load-string (format #f "solve report-files edit ~a filename ~s" list_item new_filename))
            (format "...OK\n\n")
        )
      ) 
  )
)


vinerm January 30, 2020 09:29

Good
 
Nice to know that it finally worked.


All times are GMT -4. The time now is 09:52.