|
[Sponsors] |
make a new data from external .txt data and save it in a UDM |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
February 22, 2020, 03:43 |
make a new data from external .txt data and save it in a UDM
|
#1 |
Member
Join Date: Jan 2020
Posts: 31
Rep Power: 6 |
HI... I have an external .txt data with 32 numbers in one column like (1, 2, 3 ... 32) I want a UDF to read this data from .txt File and add timestep in another column(change in each timestep) and save it in a UDM like(0.001,1; 0.001,2; ... 0.001, 32; next time step : 0.002,1 ; 0.002,2; ...0.002,32; ...)
who can help me? (see the picture) thanks |
|
February 22, 2020, 10:02 |
Clarity
|
#2 |
Senior Member
|
Your requirement is not very clear.
To read a file, you can use standard fscanf in C and then save the data in a vector variable. To write it, fprintf is used. Do note if writing in parallel, you have to be little careful.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
February 22, 2020, 12:03 |
|
#3 | |
Member
Join Date: Jan 2020
Posts: 31
Rep Power: 6 |
Quote:
http://s7.picofile.com/file/8388989618/X_data.txt.html |
||
February 22, 2020, 15:37 |
Objective
|
#4 |
Senior Member
|
The link seems to be little fishy and inaccessible at my end. Could you explain the objective since adding an extra column containing only time values seems to be of little value by itself?
Though UDMs are ordinary C variables yet they serve a different objective. UDMs are meant to be used only if the values to be stored are varying across space. The data you have seems to have no such variation. You may attach the file directly at the forum or send via PM
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
February 23, 2020, 02:12 |
|
#5 | |
Member
Join Date: Jan 2020
Posts: 31
Rep Power: 6 |
Quote:
here the attachment is my numbers |
||
February 23, 2020, 06:00 |
Udf
|
#6 |
Senior Member
|
In that case, it will be better to have a look at your current UDF to find out why two of the values being fetched are incorrect.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
February 23, 2020, 23:46 |
|
#7 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
show your UDF here, explain errors with that code
__________________
best regards ****************************** press LIKE if this message was helpful |
|
February 24, 2020, 01:58 |
|
#8 | |
Member
Join Date: Jan 2020
Posts: 31
Rep Power: 6 |
Quote:
my UDF loop for calculating the Phi is like this: begin_f_loop(f,t) { F_CENTROID(x,f,t); yy = x[0]; F_UDMI(f, t, 0) = 1-cos((PI/2)*(yy/L)); } end_f_loop(f,t) the attachment is the file output for Phi in two timesteps, and the problem is with the location of the 0 & 1 in the file output! but the Phi data is like the attachment!it must start from 0 to 1 and then end with 0! but it seems when it comes to the right edge of the blade the mistake happens and calculates and report both edge numbers instead of just the right edge! |
||
February 24, 2020, 02:51 |
Cell values
|
#9 |
Senior Member
|
If blade is a cell zone, then I'd recommend using C_CENTROID and not F_CENTROID and store in C_UDM. An immediate benefit is that you do not have to write data to file, until and unless you want to use file for something else. You can directly plot the contours of the C_UDM. I suppose the code you posted in not complete since many variables are undefined.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
February 24, 2020, 04:07 |
|
#10 | |
Member
Join Date: Jan 2020
Posts: 31
Rep Power: 6 |
Quote:
here is my UDF: #include "udf.h" #define PI 3.141592654 #define ID 3 real xold=0.0;real yold=0.0; real uold=0.0;real vold=0.0; real dx=0.0e0;real dy=0.0e0; real L=0.03; DEFINE_EXECUTE_AT_END(ForceCalculate) { real Fy=0.0e0; real x[ND_ND]; real yy; real C=1.38e-9; real teta=3.69e-6; real my=3.87e-5; real kyy=3.6; real ky=kyy+((teta*teta)/C); real zety=0.0; //----------------------------------- real wny=sqrt(ky/my); real cy=2.0e0*my*wny*zety; real wdy=wny*sqrt(1.0e0-zety*zety); //----------------------------------- real ts=CURRENT_TIMESTEP; real time=CURRENT_TIME; //----------------------------------- real Ay,By,y; FILE *fout; real NV_VEC(WS); real area[ND_ND]; real Fpy = 0.0; real Fvy=0.0; Domain *d= Get_Domain(1); Thread *t=Lookup_Thread(d,ID); face_t f; begin_f_loop(f,t) { F_CENTROID(x,f,t); yy = x[0]; F_UDMI(f, t, 0) = 1-cos((PI/2)*(yy/L)); } end_f_loop(f,t) begin_f_loop(f, t) if (PRINCIPAL_FACE_P(f,t)) { F_AREA(area,f,t); Fpy+=L*area[1]*F_P(f,t)*F_UDMI(f, t, 0); } fout = fopen ("data2D.out","a"); fprintf(fout," %f %f \n",time,F_UDMI(f, t, 0)); fclose(fout); end_f_loop(f, t) Fy = Fpy; #if RP_NODE /* SERIAL or NODE */ Fy=PRF_GRSUM1(Fy); #endif /* RP_NODE */ // Message0(" k=%g wd= %g Fy=%g\n",k,wd,Fy); // Message0(" time=%g xold= %g deltaT=%g\n",time,xold,ts); node_to_host_real_1(Fy); /* Does nothing in SERIAL */ #if !RP_NODE /* SERIAL or HOST */ Ay=yold-Fy/ky; By=(vold+zety*wny*Ay)/wdy; y=exp(-zety*wny*ts)*(Ay*cos(wdy*ts)+By*sin(wdy*ts))+Fy/ky; vold=-zety*wny*(y-Fy/ky)+wdy*exp(-zety*wny*ts)*(By*cos(wdy*ts)-Ay*sin(wdy*ts)); dy=y-yold; yold=y; //----------------------------------- //----------------------------------- fout = fopen ("data2DD.out","a"); fprintf(fout," %f %f %f %f\n",time,yold,Fy,vold); fclose(fout); #endif /* !RP_NODE */ |
||
February 24, 2020, 04:33 |
File writing
|
#11 |
Senior Member
|
The issue is with file writing. This needs to be done inside the Face loop, else, only the values for the last face would be written. And even that is not guaranteed because f is unavailable outside face loop.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
February 24, 2020, 04:57 |
|
#12 |
Member
Join Date: Jan 2020
Posts: 31
Rep Power: 6 |
do you have any offer for this? I don't know what should I do!
|
|
February 24, 2020, 04:58 |
|
#13 |
Member
Join Date: Jan 2020
Posts: 31
Rep Power: 6 |
||
February 24, 2020, 05:14 |
Order of commands
|
#14 |
Senior Member
|
Just move fprintf commands inside the begin_f_loop {} end_f_loop. Keep fopen and fclose outside the loop.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
February 24, 2020, 05:39 |
|
#15 |
Member
Join Date: Jan 2020
Posts: 31
Rep Power: 6 |
||
February 24, 2020, 05:48 |
Reasons
|
#16 |
Senior Member
|
Fluent getting stuck might have other reasons as well. For the time being, you need to check if the file written by Fluent is as expected by you or not. If not, then there is some other issue. If it has not written the file, then the file is most likely within the cache. Just kill Fluent and file will be written.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
February 24, 2020, 07:29 |
|
#17 | |
Member
Join Date: Jan 2020
Posts: 31
Rep Power: 6 |
Quote:
maybe this is better for me to enter the X[0] manually from the external file (but how?!) |
||
February 24, 2020, 07:40 |
Order
|
#18 |
Senior Member
|
You cannot enter x[0] manually since it is read from the mesh. I suppose the issue is that you are expecting numbers to be in ascending or descending order. That's not how Fluent operates. The loop is not from smallest value to largest, rather from ID 1 to ID max. Try printing value of f (it is an integer) in the file and you will see that these values start from 1 and go until the end of number of faces.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
February 24, 2020, 11:24 |
|
#19 | |
Member
Join Date: Jan 2020
Posts: 31
Rep Power: 6 |
Quote:
anyway, I don't know what can I do now!!! |
||
February 24, 2020, 11:30 |
Significance of Order
|
#20 |
Senior Member
|
The values are not sorted in an ascending or descending order, however, that does not make the calculations wrong. Calculations of your parameters that depend on values of x will be correct. So would be the values saved in UDMs.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
Tags |
#fluent #udf #data |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[General] "Save Data" from "Plot Over Line" for a single type of data | HakikiCanakkaleli | ParaView | 1 | March 5, 2022 22:39 |
[General] Save Data for all time steps | mvdl1996 | ParaView | 3 | March 30, 2021 02:12 |
X Y PLOT - Save the data | sidam | STAR-CCM+ | 3 | July 9, 2013 08:35 |
How to save 2-D data in contour plot | mssound | FLUENT | 0 | February 15, 2010 14:01 |
Save data | massimo | Siemens | 0 | November 18, 2002 05:35 |