CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

make a new data from external .txt data and save it in a UDM

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree4Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 22, 2020, 03:43
Default 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
etedalgara is on a distinguished road
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

etedalgara is offline   Reply With Quote

Old   February 22, 2020, 10:02
Default Clarity
  #2
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
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.
vinerm is offline   Reply With Quote

Old   February 22, 2020, 12:03
Default
  #3
Member
 
Join Date: Jan 2020
Posts: 31
Rep Power: 6
etedalgara is on a distinguished road
Quote:
Originally Posted by vinerm View Post
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.
Thank you my friend, I used this before and occurred some mistake! look at the link below, this is my external data with 32 numbers, I want a UDF to change it into the file with Two Columns(one is timestep and another one is the 32 numbers(look at the picture from my first post)) and I want to save this new file in the UDM ...
http://s7.picofile.com/file/8388989618/X_data.txt.html
etedalgara is offline   Reply With Quote

Old   February 22, 2020, 15:37
Default Objective
  #4
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
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.
vinerm is offline   Reply With Quote

Old   February 23, 2020, 02:12
Default
  #5
Member
 
Join Date: Jan 2020
Posts: 31
Rep Power: 6
etedalgara is on a distinguished road
Quote:
Originally Posted by vinerm View Post
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
I want to create a database that previously my UDF showed but two of its values were incorrect, and now I manually enter and modify the numbers! (the numbers are calculate from X[0] over a blade but two of the values was incorrect and my UDF Count that wrong)
here the attachment is my numbers
Attached Files
File Type: txt X_data.txt (487 Bytes, 9 views)
etedalgara is offline   Reply With Quote

Old   February 23, 2020, 06:00
Default Udf
  #6
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
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.
etedalgara likes this.
__________________
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.
vinerm is offline   Reply With Quote

Old   February 23, 2020, 23:46
Default
  #7
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
show your UDF here, explain errors with that code
etedalgara likes this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   February 24, 2020, 01:58
Default
  #8
Member
 
Join Date: Jan 2020
Posts: 31
Rep Power: 6
etedalgara is on a distinguished road
Quote:
Originally Posted by vinerm View Post
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.
ok ... I want to loop over a 2D blade, I have a problem in calculating the Phi (the formula in the picture, X change from 0 to L so Phi change from 0 to 1)
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!


Attached Files
File Type: txt Phi.txt.txt (1.3 KB, 2 views)
etedalgara is offline   Reply With Quote

Old   February 24, 2020, 02:51
Default Cell values
  #9
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
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.
vinerm is offline   Reply With Quote

Old   February 24, 2020, 04:07
Default
  #10
Member
 
Join Date: Jan 2020
Posts: 31
Rep Power: 6
etedalgara is on a distinguished road
Quote:
Originally Posted by vinerm View Post
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.
No, my blade is not a Zone, I just have one Zone as fluid, maybe I should loop over the nodes on the blade?!
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 */
etedalgara is offline   Reply With Quote

Old   February 24, 2020, 04:33
Default File writing
  #11
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
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.
vinerm is offline   Reply With Quote

Old   February 24, 2020, 04:57
Default
  #12
Member
 
Join Date: Jan 2020
Posts: 31
Rep Power: 6
etedalgara is on a distinguished road
Quote:
Originally Posted by vinerm View Post
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.
do you have any offer for this? I don't know what should I do!
etedalgara is offline   Reply With Quote

Old   February 24, 2020, 04:58
Default
  #13
Member
 
Join Date: Jan 2020
Posts: 31
Rep Power: 6
etedalgara is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
show your UDF here, explain errors with that code
what do you think about it, Alexander?
etedalgara is offline   Reply With Quote

Old   February 24, 2020, 05:14
Default Order of commands
  #14
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
Quote:
Originally Posted by etedalgara View Post
do you have any offer for this? I don't know what should I do!
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.
vinerm is offline   Reply With Quote

Old   February 24, 2020, 05:39
Default
  #15
Member
 
Join Date: Jan 2020
Posts: 31
Rep Power: 6
etedalgara is on a distinguished road
Quote:
Originally Posted by vinerm View Post
Just move fprintf commands inside the begin_f_loop {} end_f_loop. Keep fopen and fclose outside the loop.
I did this and fluent hang up at the end of the first time step!
etedalgara is offline   Reply With Quote

Old   February 24, 2020, 05:48
Default Reasons
  #16
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
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.
vinerm is offline   Reply With Quote

Old   February 24, 2020, 07:29
Default
  #17
Member
 
Join Date: Jan 2020
Posts: 31
Rep Power: 6
etedalgara is on a distinguished road
Quote:
Originally Posted by vinerm View Post
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.
the hang up is because of the change in the UDF(fprintf)! now I found out the main problem is in yy=X[0] calculating(again in the left and right side of the blade edge! x=0& x=L=0.03 )! this loop over the blade(the length of the blade is 0.03) and the yy output file is like the file below(for 1 timestep)!
maybe this is better for me to enter the X[0] manually from the external file (but how?!)
Attached Files
File Type: txt x_data.txt (1.3 KB, 4 views)
etedalgara is offline   Reply With Quote

Old   February 24, 2020, 07:40
Default Order
  #18
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
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.
etedalgara likes this.
__________________
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.
vinerm is offline   Reply With Quote

Old   February 24, 2020, 11:24
Default
  #19
Member
 
Join Date: Jan 2020
Posts: 31
Rep Power: 6
etedalgara is on a distinguished road
Quote:
Originally Posted by vinerm View Post
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.
thank you, you were right, f start from 0 to 61 Exactly how many faces I have but I still think that I can enter X[0] manually because this repeats every time steps and just change when I change my test case!
anyway, I don't know what can I do now!!!
etedalgara is offline   Reply With Quote

Old   February 24, 2020, 11:30
Default Significance of Order
  #20
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
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.
vinerm is offline   Reply With Quote

Reply

Tags
#fluent #udf #data

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 01:38.