|
[Sponsors] |
March 23, 2019, 01:50 |
Getting error while reading file in udf
|
#1 |
Member
Durgesh
Join Date: Oct 2018
Posts: 34
Rep Power: 8 |
Hello!
I am reading a text file in UDF and storing it in user memory but I am getting either segmentation fault or fl process could not be started error. Firstly I stored the values in user memory through udf when fluent processing is going on and then I export the data and saved it in a lamda.txt file. This file has to be read in other UDF for other calculation. Below code is used for reading a file in UDF: DEFINE_EXECUTE_AT_END(read_data) { cell_t c; Thread *t; Domain *d; real data[800]; FILE*fp; fp= fopen("lamda.txt","r"); if(fp==NULL) Message("file can't be open \n'"); else { Message("file is opened \n"); for(j=0;j<800;j++) { fscanf(fp,"%f",data[j]); } } fclose(fp); for(j=0;j<800;j++) C_UDMI(c,t,65)=data[j]; d=Get_Domain(1); ------ remaining codes --- } I am showing only data reading part because the fault is in these lines and also expecting data should match with the cells from previous cell value calculated through other udf. Thank you! |
|
March 24, 2019, 09:45 |
|
#2 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Did you add 66 user defined memories?
|
|
March 24, 2019, 09:55 |
|
#3 |
Member
Durgesh
Join Date: Oct 2018
Posts: 34
Rep Power: 8 |
Yes. In my udf I am using 66 user memories for storing values from different calculations. Error is in the line"C_UDMI(c,t,65)=data[j]" while storing from array to user memory. Please help me to remove it.
Thank you. |
|
March 24, 2019, 14:44 |
|
#4 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Aha, I see it now.
Want to put it in the (66th) memory location of cell c of thread t, but you never declared what cell c or thread t are. You have already declared that c is a cell and that t is a thread, but you also have to tell Fluent which cell and which thread. And you should take care that it is in EXACTLY the same order as in which you saved them. How to do that: I don't know, I don't know how you saved them. And if you also don't know, you let Fluent decide, and Fluent can change its mind every time that you upgrade to a new version. Even though I don't know what you want to do with this code, I can tell you that probably this is not the way to do this. If you can explain what you really want to achieve, somebody might tell you a better method. |
|
March 25, 2019, 00:48 |
|
#5 |
Member
Durgesh
Join Date: Oct 2018
Posts: 34
Rep Power: 8 |
Thank you Pakk for your reply.
I am solving a solidification problem in which I want to calculate lambda (secondary dendrite arm spacing) for all the cells. This is my first calculation. Once I obtained lambda for all the cells, I have to use this value for further calculation in another udf. In order to use the values in udf, I am reading a text file which contains lambda values for all the cells and this was obtained by exporting the data and saving it in .txt file. Now while reading the data as shown above in the code, I am getting an error. You are saying that I am not specifying the particular cell and thread in saving the data. Could you please tell me how to do that thing? I hope I am able to explain the problem what I want to solve. Thank you |
|
March 25, 2019, 01:34 |
|
#6 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
load both your UDF's in that case you may use SAME UDMI in both models. no input_output is needed
(if you write some data using first UDF_1 into UDMI_1 you may access it in UDF_2) best regards |
|
March 25, 2019, 10:24 |
|
#7 |
Member
Durgesh
Join Date: Oct 2018
Posts: 34
Rep Power: 8 |
Thank you for your reply.\
I suppose both the models should be solved in the same fluent case file in which my first udf calculation has been done otherwise if I load both the UDFs in another fluent case file with same UDMIs after initializing, UDMI values become initialized. Another thing I want to know, I am calculating lambda in interior cells using custom field function with filed function as one UDMI, so why does it calculate on the boundary? Also, it is a 2D problem I am looping across cells, should I loop across the faces? regards |
|
March 25, 2019, 21:08 |
|
#8 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
what do you mean under "interior cells" ? Is it domain without boundaries?
there are two main possible loops in UDF: through cells and through faces. Probably you have a loop though cells. Only you know, do yu need information on boundaries or not. It depends on your goals and model. If you need this information for simulation, than you should make new loop across faces. best regards |
|
March 25, 2019, 22:42 |
|
#9 |
Member
Durgesh
Join Date: Oct 2018
Posts: 34
Rep Power: 8 |
Yes, it is domain without boundaries and I need values only in that domain, not at the boundaries. So, I am looping across cells only. Then also it is giving me boundaries values. I need values for that domain only and these values should be correct, does not get affected due to the boundary calculation.
Regards |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[OpenFOAM.org] Error creating ParaView-4.1.0 OpenFOAM 2.3.0 | tlcoons | OpenFOAM Installation | 13 | April 20, 2016 18:34 |
what is swap4foam ?? | AB08 | OpenFOAM | 28 | February 2, 2016 02:22 |
[swak4Foam] Problem installing swak_2.x for OpenFoam-2.4.0 | towanda | OpenFOAM Community Contributions | 6 | September 5, 2015 22:03 |
[swak4Foam] Error bulding swak4Foam | sfigato | OpenFOAM Community Contributions | 18 | August 22, 2013 13:41 |
ParaView Compilation | jakaranda | OpenFOAM Installation | 3 | October 27, 2008 12:46 |