|
[Sponsors] |
Read txt file and import values to source term. |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
March 22, 2010, 14:18 |
|
#21 |
New Member
C.K.
Join Date: Mar 2010
Posts: 18
Rep Power: 16 |
I have checked it again , I can not find any mistakes in the procedure...I ll be waiting for you to check it out maybe is something that I dont understand...
Constantine |
|
March 22, 2010, 15:38 |
|
#22 |
New Member
C.K.
Join Date: Mar 2010
Posts: 18
Rep Power: 16 |
I checked it again according also to the UDF manual step by step...but the error occurs again I also tried to build the code with nmake and then put it into fluent but i have the same problems...
|
|
March 22, 2010, 18:14 |
|
#23 |
New Member
C.K.
Join Date: Mar 2010
Posts: 18
Rep Power: 16 |
Ok i figured out one problem! In fscanf (rfile, "%f",&plasma[i]); the symbol & was missing.Now ive tried this code with the first simplified grid of the 8 cells and it worked fine! But when im going to 30000 the access violation error occurs after the 1st iteration!
And also when I execute on demand the readdata udf i cant see the messages on the fluent's screen ( of the open and close file) and also i can not see anything else so that i can check if the reading of the data is proper or not(ive tried to print on the screen some values of the plasma array but nothing showed up) !! ill never manage it? :P |
|
March 23, 2010, 16:12 |
|
#24 |
Senior Member
Micael
Join Date: Mar 2009
Location: Canada
Posts: 157
Rep Power: 18 |
Well done! You find the error in the code.
I try the UDFs and do not have any problem. The problem can comes from your data. To help you diagnose the problem, add the following lines into the DEFINE_ON_DEMAND function: /* add this at the begining after similar lines */ FILE *wfile; wfile = fopen("data_rewriten.txt", "w"); /* add this line into the loop, after the fscanf line */ fprintf(wfile, "plasma[%i] = %g\n", i, &plasma[i]); /* add this after the current fclose line */ fclose(wfile); These additions will produce a new file, data_rewriten.txt, when you will read the data. Then check into that file, it should be the same as data.txt, except that plasma[i] = is added at the beginning of each line (it maybe useful to know the line number). I would not be surprise if data_rewriten.txt doesn't contain what you expect. That can help to figure out the problem. Do you have only one source (one value) per line? It should, otherwise the code will not work properly. It is strange to you do not see the messages on the screen. Do you see them with your simple case (8 cells)? -------------- Edit: I added a line to my post Last edited by Micael; March 23, 2010 at 20:50. |
|
March 23, 2010, 16:23 |
|
#25 |
New Member
C.K.
Join Date: Mar 2010
Posts: 18
Rep Power: 16 |
Hurrayyyyyyyyyy!!!! I did it!!!Well i dont know if my solution is the best but i Interpreted first the readdata code and the data were written in the file that i specified!and then after executing it on demand i interpreted my other code! It seems that it works pretty good now!! And the computational time is reasonable not that far than without the source term on!!!
I am sure that something new will pop up soon though...so I hope that we will be on touch hehe Thank you Mikael so so so much! I hope I can pay back the help someday!! Greek cheers from France! |
|
March 23, 2010, 16:49 |
|
#26 |
Senior Member
Micael
Join Date: Mar 2009
Location: Canada
Posts: 157
Rep Power: 18 |
Ça m'a fait plaisir.
|
|
June 9, 2011, 04:33 |
reading external data
|
#27 | |
Member
EH
Join Date: Dec 2010
Posts: 61
Rep Power: 16 |
Hi,
I have been following this thread as it relates to the problem I am facing. Initially you had a 2x4 grid and later a grid of 30000. May I know if this 30000 cells are uniformly distributed or are they grids made up of triangular cells. Is there still a pattern that fluent reads that determines which grid belong to which data? Just a brief of what I am doing or need to do. At the moment, I have a grid in Fluent. I intend to export the grid points where in each grid point, I will calculate the force using my own codes. Once the force on each grid point is calculated, I would like FLUENT to read it as input in the NS equation. I am still trying to comprehend how FLUENT will make sure the data in my .txt file correspond to the exact grid in the model. I look forward to your reply. Thank you very much. Sincerely, EH Quote:
|
||
March 6, 2012, 11:54 |
|
#28 | |
Member
Yolk
Join Date: Nov 2011
Posts: 38
Rep Power: 15 |
Quote:
Yannian |
||
March 6, 2012, 16:06 |
|
#29 | |
Member
Yolk
Join Date: Nov 2011
Posts: 38
Rep Power: 15 |
Quote:
I have one question that which directory should I put the txt file into? Such as you use 'fopen data.txt' where is the 'data.txt', in the same directory as case file or somewhere else? When I follow your post to use execute on demand there is something wrong, so I guess the problem lies in the directory of 'data.txt'. thanks! Yannian |
||
March 6, 2012, 17:57 |
|
#30 |
Senior Member
Micael
Join Date: Mar 2009
Location: Canada
Posts: 157
Rep Power: 18 |
I don't have stuff at hand now, but I think I put the file in the directory of the case file. What is the problem?
|
|
March 7, 2012, 05:12 |
|
#31 |
Member
Yolk
Join Date: Nov 2011
Posts: 38
Rep Power: 15 |
Hi Micael,
I use execute on demand to generate a array follow your example. Compile work includes building and loading are both Okay(I use net framework sdk2.0), when I click 'execute on demand', but the fluent give error as follows: Error: FLUENT received fatal signal (ACCESS_VIOLATION) 1. Note exact events leading to error. 2. Save case/data under new name. 3. Exit program and restart to continue. 4. Report error to your distributor. Error Object: #f the code I write is as follows /*generating an array pre[16]*/ #include "udf.h" extern real pre[16]; DEFINE_ON_DEMAND(read_data) { int i; FILE *rfile; /* declare a FILE pointer */ FILE *wfile; rfile = fopen("p.txt", "r"); /* open file for reading */ wfile = fopen("data_rewriten.txt", "w"); Message("file opened\n"); /* loop to read file */ i=0; /* initialize before to loop */ for (i=0;i<15;i++) { fscanf (rfile, "%f", pre[i]); /* that supposes one value per line */ fprintf(wfile, "pre[%i] = %g\n", i, &pre[i]); } fclose(rfile); fclose(wfile); Message("file closed\n"); } /*define profile load the array*/ #include "udf.h" real pre[16]; DEFINE_PROFILE(inlet_velocity,thread,index) { int i; face_t f; i=1; begin_f_loop(f,thread) /* loops over all faces in the thread passed in the DEFINE macro argument */ { F_PROFILE(f,thread,index) = pre[i]; i=i+1; } end_f_loop(f,thread) } p.txt is as follows 0 -5 -10 -15 -20 -25 -30 -35 -35 -30 -25 -20 -15 -10 -5 0 |
|
March 7, 2012, 10:46 |
|
#32 |
Senior Member
Micael
Join Date: Mar 2009
Location: Canada
Posts: 157
Rep Power: 18 |
Do these messages execute:?
Message("file opened\n"); Message("file closed\n"); That is, do you see the messages in the command window before you see the error message? First of all, identify the line or lines causing the problem. Put a message command in the very first line of DEFINE_ON_DEMAND. Something like: DEFINE_ON_DEMAND(read_data) { Message("test\n"); If the message display, then the problem is in some lines further down. In that case, downshift the message by one line until you cannot see the message before the error happen. |
|
March 7, 2012, 13:27 |
|
#33 |
Member
Yolk
Join Date: Nov 2011
Posts: 38
Rep Power: 15 |
There are nothing else except the ERROR on the command console, so I didn't see 'file opened' and any other meesage. I tried your advice of writing 'Message("test/n")'on the first line after '{', the thing is the same that I only get the ERROR of fluent gives. Do you have advices to the problem?
|
|
March 7, 2012, 13:57 |
|
#34 |
Member
Yolk
Join Date: Nov 2011
Posts: 38
Rep Power: 15 |
Hi Micael,
Fortunatelly I have get the message 'file opened' and 'file closed' on the command line, and 'data_rewriten.txt' which I write data into. However the data in it is not from the file 'p.txt', all the data in 'data_rewriten.txt' is pre[1] = 5.5335e-316 pre[2] = 5.5335e-316and so on. So the data is not from what I program. Thank you for your nice idea! I will continue on it. |
|
March 7, 2012, 16:19 |
|
#35 |
Senior Member
Micael
Join Date: Mar 2009
Location: Canada
Posts: 157
Rep Power: 18 |
As you can see in my old post (#24), this line:
Code:
fprintf(wfile, "plasma[%i] = %g\n", i, &plasma[i]); Code:
fprintf(wfile, "pre[%i] = %g\n", i, &pre[i]); Code:
fprintf(wfile, "%g\n", i, &pre[i]); Also, do you really need to write data back into another file? That was only suggested for verification purpose. |
|
March 8, 2012, 04:28 |
|
#36 |
Member
Yolk
Join Date: Nov 2011
Posts: 38
Rep Power: 15 |
Hi Micael,
Thank you very much!I pretty appreciate your patience to help.The problem has been figured out. The problems maybe are: the name of directory shouldn't has space;The array should be pre[15],not pre[16];the variable of type of pre[15] should be float and not be real;there is '&' in front of pre[i] in the function of fprintf; The code can be run is posted it as follows. #include "udf.h" extern real plasma[16]; DEFINE_ON_DEMAND(read_data) { int i; FILE *rfile; /* declare a FILE pointer */ rfile = fopen("D:\yyang9\DISK\March\2d\p.txt", "r"); /* open file for reading */ Message("file opened\n"); /* loop to read file */ i=0; /* initialize before to loop */ for (i=0;i<15;i++) { fscanf (rfile, "%f", &plasma[i]); /* that supposes one value per line */ } fclose(rfile); Message("file closed\n"); } /*the DEFINE_PROFILE array use array pre[15]*/ #include "udf.h" float pre[15]; DEFINE_PROFILE(inlet_pressure,thread,index) { int i; face_t f; for (i=0; i<16; i++) { Message("%3.2f",pre[i]);/*15*/ } printf("\n"); i=0; begin_f_loop(f,thread) /* loops over all faces in the thread passed in the DEFINE macro argument */ { F_PROFILE(f,thread,index) = pre[i]; i=i+1; } end_f_loop(f,thread) } the file of 'p.txt' -20 -30 -40 -20 -20 -30 -40 -300 -500 -300 -400 -200 -20 -30 -40 -20 |
|
August 26, 2015, 08:26 |
|
#37 |
New Member
Batuhan Savaskan
Join Date: Aug 2015
Posts: 9
Rep Power: 11 |
Hello Everyone;
I am using fluent and I have transient experimental temperature data for a surface in excel format. I want to import them to fluent and run. How can I do that? Is there anyone who has the code of this. Thank you very much. |
|
July 20, 2016, 12:36 |
|
#38 | |
New Member
Sagar
Join Date: Apr 2016
Posts: 23
Rep Power: 10 |
Quote:
Its already 6 years since this post. I'm currently having similar kind of problem. I am stuck with problem for long time. I have written a UDF to read property of DPM from a file which contains temperature and density values in tabulated fashion. I want to first read the file and assign the read-in values to the arrays. After this through another UDF I want to find the density by linear interpolation (which will happen wherever the particle is during run-time). I followed this thread which is very similar to my case. but the problem is that it is not getting compiled. I am able to compile other UDF's but I'm not able to specifically build this UDF. I'm suspecting that it has to do with the extern variable, because if I remove this everything works fine. Do you have any idea how this can be solved? Any help would be appreciated. Regards |
||
July 20, 2016, 13:09 |
|
#39 |
New Member
Sagar
Join Date: Apr 2016
Posts: 23
Rep Power: 10 |
I will post both the codes, one to read file, which reads temperature, density values (temperature values are written in 1K steps, denisty values are also tabulated corresponding to each of temperature values) and other to carry out the value of density, which should happen during run-time when solver gives temperature value to my UDF.
UDF to read file: #include "udf.h" extern float temparr[725],rhoarr[725]; DEFINE_ON_DEMAND(read_data) { int i=0; FILE *fp; fp = fopen("liq_prop.txt", "r"); printf("file opened\n"); for (i;i<726;i++) { fscanf (fp, "%f %f %*f %*f %*f", &temparr[i], &rhoarr[i]); /*read only temperature and density and other columns are suppressed. Even If I read all the columns and assign them to different arrays error remains" } fclose(fp); printf("file closed\n"); } UDF to calculate density: #include "udf.h" #include "stdio.h" #include "stdlib.h" #include "math.h" float temparr[725],rhoarr[725]; DEFINE_DPM_PROPERTY(particle_density,c,t,p,T) { double tgiven = P_T(p); int i, j; /*double temparr[725], rhoarr[725];*/ double frac,intpart_temp; double rhocalc,tempup,templow, tcrit=725.9; frac = modf(tgiven, &intpart_temp); /*to get integer part of real number*/ for(i=0;i<726;i++) { if(tgiven>tcrit) { rhocalc = rhoarr[725]; break; } else if(temparr[i] == intpart_temp) { j = i; templow = temparr[i]; tempup = templow + 1; rhocalc = rhoarr[j] + ((rhoarr[j+1]-rhoarr[j]) * (tgiven - templow)/(tempup-templow)); } } return rhocalc; } If I compile both UDF's together, after I press build I don't get any link messages. When I press load, I get an error: Not able to find libudf.dll. This is not the problem with other UDF's though. When I interpret the read_data UDF, I don't get any file open and close messages on console and I get error: file_readd.c: line 18: label "temparr" not found (pc=44). file_readd.c: line 18: label "rhoparr" not found (pc=52). Please suggest what can I do to correct it. |
|
July 20, 2016, 15:04 |
|
#40 |
Senior Member
Micael
Join Date: Mar 2009
Location: Canada
Posts: 157
Rep Power: 18 |
I am not a fscanf expert so looking at your code I would first verify fscanf by making thing simpler by creating by hand two files, one for temperature and one for density. Each file have only one column in it (you will have to create those file yourself)
then: Code:
fp = fopen("liq_prop.txt", "r"); Code:
fp1 = fopen("temp.txt", "r"); fp2 = fopen("rho.txt", "r"); Code:
fscanf (fp, "%f %f %*f %*f %*f", &temparr[i], &rhoarr[i]); Code:
fscanf (fp, "%f", temparr[i]); fscanf (fp, "%f", rhoarr[i]); Last edited by Micael; July 20, 2016 at 18:01. |
|
Tags |
array, file, source, txt, udf |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How can I import a momentum source term from a dat | May Huang | FLUENT | 1 | September 5, 2011 06:50 |
help: How can I import a source? | May Huang | FLUENT | 1 | September 5, 2011 06:49 |
how do I import tecplot file to fluent | Kangello | FLUENT | 0 | December 2, 2009 09:28 |
Errors running allwmake in OpenFOAM141dev with WM_COMPILE_OPTION%3ddebug | unoder | OpenFOAM Installation | 11 | January 30, 2008 21:30 |
Importing I-DEAS unv file | hbetb | FLUENT | 1 | August 10, 2001 14:22 |