CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT

Journal or Scheme to loop through report files

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree2Likes
  • 1 Post By vinerm
  • 1 Post By DEd

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 27, 2020, 17:04
Default Journal or Scheme to loop through report files
  #1
DEd
Member
 
Daniel Edebro
Join Date: Feb 2016
Location: Gothenburg
Posts: 39
Rep Power: 7
DEd is on a distinguished road
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.
DEd is offline   Reply With Quote

Old   January 28, 2020, 08:02
Default Prefer some other method
  #2
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 33
vinerm will become famous soon enough
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
vinerm is offline   Reply With Quote

Old   January 28, 2020, 09:44
Thumbs up I love to but...
  #3
DEd
Member
 
Daniel Edebro
Join Date: Feb 2016
Location: Gothenburg
Posts: 39
Rep Power: 7
DEd is on a distinguished road
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*
DEd is offline   Reply With Quote

Old   January 28, 2020, 09:55
Default Variables
  #4
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 33
vinerm will become famous soon enough
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.
vinerm is offline   Reply With Quote

Old   January 28, 2020, 10:11
Default Yes but..
  #5
DEd
Member
 
Daniel Edebro
Join Date: Feb 2016
Location: Gothenburg
Posts: 39
Rep Power: 7
DEd is on a distinguished road
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.
DEd is offline   Reply With Quote

Old   January 28, 2020, 10:32
Default list-ref could be used
  #6
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 33
vinerm will become famous soon enough
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.
vinerm is offline   Reply With Quote

Old   January 29, 2020, 00:23
Default
  #7
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 1,852
Rep Power: 29
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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
AlexanderZ is offline   Reply With Quote

Old   January 30, 2020, 04:47
Default Solved?
  #8
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 33
vinerm will become famous soon enough
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.
vinerm is offline   Reply With Quote

Old   January 30, 2020, 04:53
Default Still can't create list of report-files
  #9
DEd
Member
 
Daniel Edebro
Join Date: Feb 2016
Location: Gothenburg
Posts: 39
Rep Power: 7
DEd is on a distinguished road
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)
	)	
)
DEd is offline   Reply With Quote

Old   January 30, 2020, 05:02
Default Solution
  #10
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 33
vinerm will become famous soon enough
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 likes this.
__________________
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.
vinerm is offline   Reply With Quote

Old   January 30, 2020, 07:25
Default
  #11
DEd
Member
 
Daniel Edebro
Join Date: Feb 2016
Location: Gothenburg
Posts: 39
Rep Power: 7
DEd is on a distinguished road
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")
         )
      )  
   )
)
anan12345 likes this.
DEd is offline   Reply With Quote

Old   January 30, 2020, 09:29
Default Good
  #12
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 33
vinerm will become famous soon enough
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.
vinerm is offline   Reply With Quote

Reply

Tags
journal, scheme

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[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
[Other] Contribution a new utility: refine wall layer mesh based on yPlus field lakeat OpenFOAM Community Contributions 57 February 1, 2015 09:25
UDF issue MASOUD Fluent UDF and Scheme Programming 14 December 6, 2012 14:39


All times are GMT -4. The time now is 06:26.