I want to read 10 case files in Ansys Fluent and for each case file there are 10 data files to be read. Ansys Fluent uses Scheme programming language. I have to managed to get some answers to individual problems in the code here ( Evaluating a floating point variable in Scheme language ) and here ( How to increase counter in a do-loop within Scheme language? ), but when collecting the individual answers I realized that I need a new code for the counter which is used to read the data files through do-loop. Here is the code with solutions from from other question included:
(do ((i 10 (+ i 1))
(j 5 (+ j 1)))
((>= i 20) 'my-return-value)
(ti-menu-load-string
(format #f "/file/read-case \"C:/DataProcessing/Case~a-time~a-sec/test/Case~a-time~a-sec.cas\"" i j i j))
(do ((datafilenum 5.100 (+ datafilenum 0.100)))
((>= datafilenum 6.000))
(ti-menu-load-string (format #f "/file/read-data \"C:/DataProcessing/Case~a-time~a-sec/test/Case~a-time~a-sec-~.3f.dat\"" i j i j datafilenum))
(ti-menu-load-string (format #f "/plot plot n \"C:/DataProcessing/Case~a-time~a-sec/test/water-vof/column-water-vof-at-~.3fs.txt\" y n n water vof y 0 1 0 16 ()" i j datafilenum))))
What I'm trying to achieve here is: read the case file
Case10-time5-sec.cas
then it reads the 10 data files and plot the answer
Case10-time5-sec-5.100.dat
Case10-time5-sec-5.200.dat
...
Case10-time5-sec-6.000.dat
Next loop:
Case11-time6-sec.cas
read the 10 data files and plot answer
Case11-time6-sec-6.100.dat
Case11-time6-sec-6.200.dat
...
Case11-time6-sec-7.000.dat
Next loop...
So, how to change datafilenum
starting with 5.100
in this code to 6.100
, 7.100
, 7.100
etc. when j
changes value in the upper loop, something like j.100
and append this value to the exported text file column-water-vof-at-~.3fs.txt
. And, of course change, 6.000
to 7.000
, 8.000
..., something like j+1.000
? This got me very confused as I have used trial and error to achieve it!
How to get the number. If j
is 6 and you want 6.1
you add 1/10
to it using standard math operations.
(define j 6)
(+ j 1/10)
; ==> 61/10 (aka 6.1 exact)
The function format
is not standard and thus there are many competing implementations. In SRFI-48 Intermediate Format Strings you can do this to get 61/10
to be displayed as 6.100
:
(format #f "~0,3F" (+ j 1/10))
; ==> "6.100"
So putting it all together:
(do ((i 10 (+ i 1))
(j 5 (+ j 1)))
((>= i 20))
(ti-menu-load-string
(format #f "/file/read-case \"C:/DataProcessing/Case~a-time~a-sec/test/Case~a-time~a-sec.cas\"" i j i j))
(do ((datafilenum (+ j 1/10) (+ datafilenum 1/10)))
((>= datafilenum (+ j 1)))
(ti-menu-load-string (format #f "/file/read-data \"C:/DataProcessing/Case~a-time~a-sec/test/Case~a-time~a-sec-~0,3F.dat\"" i j i j datafilenum))
(ti-menu-load-string (format #f "/plot plot n \"C:/DataProcessing/Case~a-time~a-sec/test/water-vof/column-water-vof-at-~0,3Fs.txt\" y n n water vof y 0 1 0 16 ()" i j datafilenum))))
If this isn't working you need to edit in which implementation you are using. eg. Racket has format
which is different, but it also supports SRFI-48 so I tested this with (require srfi/48)
. I prefer to use a SRFI rather than the implementations version since porting to a different implementation or revision of RNRS later will be easier.
Ansys Fluent does not have a clear Scheme standard and no full numeric tower. The use "a mixture of MIT Scheme 3 and 4".
When looping through floating point numbers there will always be issues because of arbitrarily accuracy especially when putting these numbers into string. As you already mentioned, Fluent does not directly support fractional number which would be exact arithmetic.
You will end up with something like this somewhen
Case11-time6-sec-6.100.dat
Case11-time6-sec-6.200.dat
...
Case11-time6-sec-6.499987987.dat
...
Case11-time6-sec-7.000.dat
The best solution I came up with so far is writing a function which evaluates a pair, which is a native and fast structure in Sheme, which contains a number and a corresponding string based on rounding.
If you are still on this topic I can expand this answer with further details.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.