CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   record a variable in UDF (https://www.cfd-online.com/Forums/fluent/38693-record-variable-udf.html)

reto November 22, 2005 01:25

record a variable in UDF
 
hello

i have an unsteady problem with an UDF. how can i record a variable by time in a file, to get a list? at the moment i use fprintf but i get only the value of the last time step.

thanks

reto

Zhang November 22, 2005 15:30

Re: record a variable in UDF
 
My suggestion:

1. Define a DEFINE_ON_DEMAND subroutine. In this subroutine you open an output file. Something like this,"ofp=fopen("out2.txt","w");"

2. Define a DEFINE_EXECUTE_AT_END subroutine. This subroutine will be executed at the end of each time step. In this subroutine your output the value of desired variables. e.g. "fprintf (ofp,"%e\n",variablename);"

3. Define another DEFINE_ON_DEMAND subroutine. In this subroutine you close the output file. "fclose(ofp);"

4. Please include,

#include "stdio.h"

#include "udf.h" and define,

FILE *ofp; at the beginning of your source code file.

5. Before you start the iteration, run the first subroutine through "Define -> User-Defined -> Execute On Demand...". Then iterate. Once the iteration finished, run the third subroutine through "Define -> User-Defined -> Execute On Demand...".

6. Hope it works. Good luck!

Zhang

reto November 23, 2005 04:01

Re: record a variable in UDF
 
many thanks for your suggestion, it works!

reto


All times are GMT -4. The time now is 12:27.