|
[Sponsors] |
Journal or Scheme to loop through report files |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
January 27, 2020, 17:04 |
Journal or Scheme to loop through report files
|
#1 |
Member
Daniel Edebro
Join Date: Feb 2016
Location: Gothenburg
Posts: 41
Rep Power: 10 |
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/ Code:
(define my-monitors-list (ti-menu-load-string "/solve/report-files/list/")) Code:
/solve/report-files/edit/{report-file-name}/file-name |
|
January 28, 2020, 08:02 |
Prefer some other method
|
#2 |
Senior Member
|
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 |
|
January 28, 2020, 09:44 |
I love to but...
|
#3 |
Member
Daniel Edebro
Join Date: Feb 2016
Location: Gothenburg
Posts: 41
Rep Power: 10 |
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 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) ) Code:
wd basename10.dat.gz Error: wta(1st) to lopeninputstring Error Object: *the-non-printing-object* |
|
January 28, 2020, 09:55 |
Variables
|
#4 |
Senior Member
|
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.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
January 28, 2020, 10:11 |
Yes but..
|
#5 |
Member
Daniel Edebro
Join Date: Feb 2016
Location: Gothenburg
Posts: 41
Rep Power: 10 |
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. |
|
January 28, 2020, 10:32 |
list-ref could be used
|
#6 |
Senior Member
|
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.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
January 29, 2020, 00:23 |
|
#7 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
if you make all settings after loading new mesh you can set all names again using TUI and save case/data as well
__________________
best regards ****************************** press LIKE if this message was helpful |
|
January 30, 2020, 04:47 |
Solved?
|
#8 |
Senior Member
|
Daniel, have you finally been able to get Fluent to do what you wanted?
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
January 30, 2020, 04:53 |
Still can't create list of report-files
|
#9 |
Member
Daniel Edebro
Join Date: Feb 2016
Location: Gothenburg
Posts: 41
Rep Power: 10 |
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) ) ) |
|
January 30, 2020, 05:02 |
Solution
|
#10 |
Senior Member
|
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.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
January 30, 2020, 07:25 |
|
#11 |
Member
Daniel Edebro
Join Date: Feb 2016
Location: Gothenburg
Posts: 41
Rep Power: 10 |
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") ) ) ) ) |
|
January 30, 2020, 09:29 |
Good
|
#12 |
Senior Member
|
Nice to know that it finally worked.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
Tags |
journal, scheme |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Other] Contribution a new utility: refine wall layer mesh based on yPlus field | lakeat | OpenFOAM Community Contributions | 58 | December 23, 2021 03:36 |
[Other] refineWallLayer Error | Yuby | OpenFOAM Meshing & Mesh Conversion | 2 | November 11, 2021 12:04 |
Writing report files and creating report definitions. | cfd_worker99 | FLUENT | 3 | June 12, 2020 13:55 |
Scheme macros inside journal files | michal.s | Fluent UDF and Scheme Programming | 5 | March 6, 2018 06:41 |
UDF issue | MASOUD | Fluent UDF and Scheme Programming | 14 | December 6, 2012 14:39 |