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 Community New Posts Updated Threads Search

Like Tree4Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 24, 2020, 13:28
Default
  #21
Member
 
Join Date: Jan 2020
Posts: 31
Rep Power: 6
etedalgara is on a distinguished road
Quote:
Originally Posted by vinerm View Post
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.
what do you offer me to do?
etedalgara is offline   Reply With Quote

Old   February 24, 2020, 15:48
Default Objective
  #22
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 wanted to fetch values of x-coordinate and then calculate the corresponding \Phi values. You have already been able to calculate those. Values are not wrong; those are just not in the order your expect, but the values are correct. If you want something more, you have to explain the requirements.
__________________
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, 19:01
Default
  #23
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
you may use 2 UDMIs:
1. save yy
2. save 1-cos((PI/2)*(yy/L));

from my point of view, you can't write to file inside first loop
because you can do it only from host

you may try this, compile it
Code:
#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));
F_UDMI(f, t, 1) = yy;
F_AREA(area,f,t);
Fpy+=L*area[1]*F_P(f,t)*F_UDMI(f, t, 0);
}
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 ("data2D.out","a");
begin_f_loop(f,t)
{
	fprintf(fout," %f %f %f\n",time,F_UDMI(f, t, 0),F_UDMI(f, t, 1));
}
end_f_loop(f,t)
fclose(fout);

fout = fopen ("data2DD.out","a");
fprintf(fout," %f %f %f %f\n",time,yold,Fy,vold);
fclose(fout);

#endif /* !RP_NODE */
}
__________________
best regards


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

Old   February 25, 2020, 03:46
Default File writing
  #24
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 are right about host not having this data, Alexander. However, file writing can be done inside the face loop. The problem is not with respect to the host rather will respect to the availability of the file to all nodes, including the host. So, all that is needed is to ensure that at any given time only one node access the file. Simpler option, of course, would be do it in Serial. However, if the case is big, you have two options. Either pass all the data to node 0 and let it do the writing or run in a sequential manner from node 0 to the node N (N being the number of parallel cores being used) and let every node write its data. You can use macro PRF_CSEND_INT to keep track of this. Look at the example DEFINE_OUTPUT_PARAMETER in UDF manual for its use
__________________
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 25, 2020, 06:55
Default
  #25
Member
 
Join Date: Jan 2020
Posts: 31
Rep Power: 6
etedalgara is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
you may use 2 UDMIs:
1. save yy
2. save 1-cos((PI/2)*(yy/L));

from my point of view, you can't write to file inside first loop
because you can do it only from host

you may try this, compile it
Code:
#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));
F_UDMI(f, t, 1) = yy;
F_AREA(area,f,t);
Fpy+=L*area[1]*F_P(f,t)*F_UDMI(f, t, 0);
}
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 ("data2D.out","a");
begin_f_loop(f,t)
{
	fprintf(fout," %f %f %f\n",time,F_UDMI(f, t, 0),F_UDMI(f, t, 1));
}
end_f_loop(f,t)
fclose(fout);

fout = fopen ("data2DD.out","a");
fprintf(fout," %f %f %f %f\n",time,yold,Fy,vold);
fclose(fout);

#endif /* !RP_NODE */
}

thank you all my friends
I will show you my main problem and what I want to do. my mesh linked too.
My main problem is with 1 cell with no moving and this causes mistake in the blade shape and I think that the problem is with the X[0] data
in the pictures, you can see the cell with no motion and the page of the article with the formulas to simulate this case! I think my Grid Motion has some mistakes too!(maybe this part: NV_V_VS(NODE_COORD(v), =, NODE_COORD(v), +, axis, *, F_UDMI(f, tf, 2)); )
thanks for your help

here is my UDF with Grid Motion!

#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));
F_UDMI(f, t, 1) = yy;
F_AREA(area,f,t);
Fpy+=L*area[1]*F_P(f,t)*F_UDMI(f, t, 0);
}
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 ("data2D.out","a");
begin_f_loop(f,t)
{
fprintf(fout," %f %f %f\n",time,F_UDMI(f, t, 0),F_UDMI(f, t, 1));
}
end_f_loop(f,t)
fclose(fout);

fout = fopen ("data2DD.out","a");
fprintf(fout," %f %f %f %f\n",time,yold,Fy,vold);
fclose(fout);

#endif /* !RP_NODE */
}

DEFINE_GRID_MOTION(beam,domain,dt,time,dtime)
{
Thread *tf = DT_THREAD(dt);
face_t f;
Node *v;
int n;
real x[ND_ND];
real yy;
real yyy[ND_ND];
real NV_VEC(axis);
real yoldd;
real bb;

/* set deforming flag on adjacent cell zone */
SET_DEFORMING_THREAD_FLAG(THREAD_T0(tf));

begin_f_loop(f,tf)
{
F_UDMI(f, tf, 2) = F_UDMI(f, tf, 0)*yold;
}
end_f_loop(f,tf);

Message ("time = %f, \n", time);

NV_D(axis, =, 0.0, 1, 0.0);

begin_f_loop(f,tf)
{
f_node_loop(f,tf,n)
{
v = F_NODE(f,tf,n);
if ( NODE_POS_NEED_UPDATE (v))
{
NODE_POS_UPDATED(v);

NV_V_VS(NODE_COORD(v), =, NODE_COORD(v), +, axis, *, F_UDMI(f, tf, 2));
}
}
}

end_f_loop(f,tf);
}





http://8upload.ir/uploads/f9239726.rar
etedalgara is offline   Reply With Quote

Old   February 25, 2020, 08:53
Default A few checks
  #26
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
1. There is no need to multiply by L in the calculation of Fpy since the area already includes it.
2. Value of yold is being calculated at the host but I do not see any host_to_node_... transfer.
3. Check the value for UDM 0 for the last face. Since you are writing value for x, check its value for the maximum x. The value should be slightly smaller than 1.
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 26, 2020, 03:26
Default
  #27
Member
 
Join Date: Jan 2020
Posts: 31
Rep Power: 6
etedalgara is on a distinguished road
Quote:
Originally Posted by vinerm View Post
1. There is no need to multiply by L in the calculation of Fpy since the area already includes it.
2. Value of yold is being calculated at the host but I do not see any host_to_node_... transfer.
3. Check the value for UDM 0 for the last face. Since you are writing value for x, check its value for the maximum x. The value should be slightly smaller than 1.
thank you for your comments really helped me
I use fluent with serial type, still, need a host to node?
sorry about these questions I am not good in UDF
and how can I fix my UDF? still, it doesn't work!
can you fix it from the article page I sent you?!
I work on it for months!
etedalgara is offline   Reply With Quote

Old   February 26, 2020, 04:15
Default Host To Node
  #28
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 serial, you do not need host to node or node to host, since this classification does not exist.

To debug the code, I'd suggest you simplify it. Do not use any equation for moving the nodes. Try moving those by a constant value, so, replace F_UDMI in node update with a small constant value. If the end node still does not show any movement, then it will be easier to find the reason. If it shows a movement, then you know that the displacement provided by the UDM is not correct. This way, it will become easier to find out the solution.
__________________
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


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 23:39
[General] Save Data for all time steps mvdl1996 ParaView 3 March 30, 2021 03:12
X Y PLOT - Save the data sidam STAR-CCM+ 3 July 9, 2013 09:35
How to save 2-D data in contour plot mssound FLUENT 0 February 15, 2010 15:01
Save data massimo Siemens 0 November 18, 2002 06:35


All times are GMT -4. The time now is 08:48.