CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   How to get a value from a data file bound to a variable in Scheme? (https://www.cfd-online.com/Forums/fluent-udf/91856-how-get-value-data-file-bound-variable-scheme.html)

Shirock August 24, 2011 14:05

How to get a value from a data file bound to a variable in Scheme?
 
Hello everyone,

I am a student from Germany and have the following problem.

During the simulation Fluent is writing the current of each iteration into a data file "I_anode.out".
I now want the value back into scheme to be able to do some calculations with it and feed Fluent a new mass-flow-rate befor the next iteration step.

I have found a an example how to read values back into scheme by Mirko Javurek and changed it for my purpose.

(let
((p (open-input-file "I_anode.out")))
(do
((x (read p) (read p)))
(
(or (number? x) (eof-object? x))
(close-input-port p)
(if (number? x) x #f)
)
)
)


The problem is that only the number is shown in the TUI and I do not have a variable to do calculations with. I tried a few ideas myself but was not able to bind the current value to a variable.

I would really appreciate if someone could help me to rewrite the program so I could to do some further calculations.

Thank you for your help!
Alexander

fox000002 August 30, 2011 08:21

Code:


(define read-data-from-file
(lambda (fn)
(let
    ((p (open-input-file "I_anode.out")))
    (do
        ((x (read p) (read p)))
        (
            (or (number? x) (eof-object? x))
            (close-input-port p)     
            (if (number? x) x #f)
        )
    )
)
)
)

(define your-var (read-data-from-file "I_anode.out"))


Shirock August 31, 2011 06:04

Thank you very much!


All times are GMT -4. The time now is 14:13.