|
[Sponsors] |
June 6, 2003, 08:05 |
UDF to read and write data
|
#1 |
Guest
Posts: n/a
|
Hi,
Does anyone know how i should go about including a section in a UDF that reads an entire data file once certain conditions are reached. I monitor the temperature at a point throughout a simulation and once that temperature reaches a certain value, i want to read in another data file without having to be at my computer to reinitialise. Any ideas? All help will be gratefully received Andy |
|
June 6, 2003, 15:14 |
Re: UDF to write data
|
#2 |
Guest
Posts: n/a
|
Hi
Follow this pice of code that I wrote for this purposes. Keep in mind that fluent does not allow you to write the filename on your screen therefore you must to change the filename on this C-code, also you have to store that information on a UDM or UDS Do not forget to request in fluent one or more than one UDM memory. (I don't know how may data do you have). In addition I paste the basic comand that you need to made this task. Hoever, you can made your code much more complex. (I left this part to you..) /************************************************** ********************/ /* UDF to read a scalar from an external file and stored in UDM Memory*/ /************************************************** ********************/ #include "udf.h" #include "sg.h" #include "dpm.h" #define UDM_RH 0 #define N_REQ_UDM 1 DEFINE_ON_DEMAND(add_data) { extern Domain* domain; cell_t cell; Thread *thread; real x[ND_ND]; real a[4]; int i; char filename[]="myfilename.txt"; FILE *sfp; /*destination file pointer*/ Message("\n FILENAME:%s\n",filename); sfp = fopen(filename, "r"); if(sfp == NULL) { Message("\n Warning: unable to open %s for reading\n", filename); } thread_loop_c(thread,domain) { begin_c_loop(cell,thread) { fscanf(sfp, "%g", &a[0]); C_UDMI(cell,thread,UDM_RH) = a[0]; } end_c_loop(cell,thread) } fclose(sfp); } |
|
June 6, 2003, 15:18 |
Re: UDF to read and write data
|
#3 |
Guest
Posts: n/a
|
Hi
Sorry I misunderstood your question you can use several functions such us define macro under comands or read and write under define UDF functions Best regards Alex Munoz |
|
June 9, 2003, 08:52 |
Re: UDF to read and write data
|
#4 |
Guest
Posts: n/a
|
Hi Alex,
How do i use read or write under define UDF functions? What line do i include in my UDF? Is it a simple as: read-file ("path/filename") Regards Mc |
|
June 9, 2003, 14:21 |
Re: UDF to read and write data
|
#5 |
Guest
Posts: n/a
|
Hi
I gave a code then compiled it, then under UDF load the library. Then under execute on demand browse the name of the code (i.e., add_data) and excecuted. However, what you want to do is totally diferent, Fluent allow you to import an external file that could contained a scalar field, boundary condition etc. If I understood you problem you want to read a data file after a certain number of iteration. Therefoer, you must to search how to create a macro. I have never made this type of work so you have to find the information by yourself. Regards Alex Munoz |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
mesh file for flow over a circular cylinder | Ardalan | Main CFD Forum | 7 | December 15, 2020 14:06 |
I/O of a real value by "DEFINE_RW_FILE" (UDF) | Pietro Asinari | Fluent UDF and Scheme Programming | 1 | August 15, 2015 20:08 |
How to read or write case by commands during simulation with Fluent | lzgwhy | FLUENT | 4 | April 20, 2011 23:02 |
using UDF to read file | Ellen | FLUENT | 5 | November 25, 2008 18:38 |
Phase locked average in run time | panara | OpenFOAM | 2 | February 20, 2008 15:37 |