
[Sponsors] 
January 29, 2020, 02:12 
UDF for blade displacement

#1 
Member
Join Date: Jan 2020
Posts: 31
Rep Power: 3 
Hi my friends ... I need to write a UDF for a blade displacement ... I should define Phi (as the picture below eq 11) to use it in another formula( as the picture below eq 10), but I can't make a loop over x to define Phi to use it! it is always one number(number 1.695913)!
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; real Phi; DEFINE_EXECUTE_AT_END(ForceCalculate) { real Fy=0.0e0; real x[ND_ND]; real yy; #if !RP_HOST /* SERIAL or NODE */ 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]; Phi = 1sin(((90*PI)/180)*(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)*Phi; } end_f_loop(f, t) Fy = Fpy; #if RP_NODE /* Perform node synchronized actions here*/ Fy=PRF_GRSUM1(Fy); Fx=PRF_GRSUM1(Fx); #endif /* RP_NODE */ #endif /* !RP_HOST */ // 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_2(Fy,Fx); /* Does nothing in SERIAL */ #if !RP_NODE /* SERIAL or HOST */ real C=3.69e6; real teta=1.38e9; real my=7.789e0; 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.0e0zety*zety); // real ts=CURRENT_TIMESTEP; real time=CURRENT_TIME; // real Ay,By,y; Ay=yoldFy/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*(yFy/ky)+wdy*exp(zety*wny*ts)*(By*cos(wdy*ts)Ay*sin(wdy*ts)); dy=yyold; yold=y; // // FILE *fout; fout = fopen ("data2D.out","a"); fprintf(fout," %f %f %f %f %f\n",time,yold,Fy,vold,Phi); fclose(fout); #endif /* !RP_NODE */ } 

January 29, 2020, 07:01 
Phi is a scalar

#2 
Senior Member

It gives only one value for Phi because Phi is declared as a scalar, i.e., it can store only one number. What you need is a vector that can store as many values of Phi as many x are there. Recommended to use UDM in place of Phi.
__________________
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. 

January 29, 2020, 07:07 
how can I do?

#3 
Member
Join Date: Jan 2020
Posts: 31
Rep Power: 3 
Thanks for your accountability, since I am poor at writing a UDF and my information is not high, can you correct this for me?


January 29, 2020, 07:10 
Suggestions

#4 
Senior Member

You should replace Phi with F_UDMI(f, t, 0) everywhere in the code. Along with that you also need to ensure that you enable one UDM in Fluent and initialize by patching it to 0. UDMs are available at UDFs > Memory.
__________________
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. 

January 29, 2020, 07:45 

#5 
Member
Join Date: Jan 2020
Posts: 31
Rep Power: 3 
again really Thank you ... to be sure that everything is ok, I want to see the Phi data in **fprintf(fout," %f %f %f %f %f\n",time,yold,Fy,vold,Phi);** as I replace the Phi with F_UDMI(f, t, 0), how can I do it?


January 29, 2020, 07:49 
Write inside the loop

#6 
Senior Member

Since Phi is not a single value, you have write your output file within the face loop. And as usual, replace Phi with UDM.
__________________
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. 

January 29, 2020, 08:07 

#7  
Member
Join Date: Jan 2020
Posts: 31
Rep Power: 3 
Quote:
I know I am a bad student!!! here is my improved UDF: Is it ok?!!!! #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; #if !RP_HOST /* SERIAL or NODE */ 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) = 1sin(((90*PI)/180)*(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); } end_f_loop(f, t) Fy = Fpy; #if RP_NODE /* Perform node synchronized actions here*/ Fy=PRF_GRSUM1(Fy); Fx=PRF_GRSUM1(Fx); #endif /* RP_NODE */ #endif /* !RP_HOST */ // 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_2(Fy,Fx); /* Does nothing in SERIAL */ #if !RP_NODE /* SERIAL or HOST */ real C=3.69e6; real teta=1.38e9; real my=7.789e0; 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.0e0zety*zety); // real ts=CURRENT_TIMESTEP; real time=CURRENT_TIME; // real Ay,By,y; Ay=yoldFy/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*(yFy/ky)+wdy*exp(zety*wny*ts)*(By*cos(wdy*ts)Ay*sin(wdy*ts)); dy=yyold; yold=y; // // FILE *fout; fout = fopen ("data2D.out","a"); fprintf(fout," %f %f %f %f %f\n",time,yold,Fy,vold,F_UDMI(f, t, 0)); fclose(fout); #endif /* !RP_NODE */ } 

January 30, 2020, 02:08 

#8 
Senior Member
Alexander
Join Date: Apr 2013
Posts: 1,778
Rep Power: 28 
compile code
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=3.69e6; real teta=1.38e9; real my=7.789e0; 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.0e0zety*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) = 1sin(((90*PI)/180)*(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); } 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=yoldFy/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*(yFy/ky)+wdy*exp(zety*wny*ts)*(By*cos(wdy*ts)Ay*sin(wdy*ts)); dy=yyold; yold=y; // // fout = fopen ("data2D.out","a"); fprintf(fout," %f %f %f %f %f\n",time,yold,Fy,vold,F_UDMI(f, t, 0)); fclose(fout); #endif /* !RP_NODE */ }
__________________
best regards ****************************** press LIKE if this message was helpful 

January 30, 2020, 03:45 
Segmentation Violation Expected

#9 
Senior Member

The code that Alexander shared will work for most of the part; I haven't checked it line by line but most likely it will do most of the work, except for writing. You should get Segmentation Violation while writing the output since f does not exist outside begin_f_loop. Therefore, any command making use of f has to be within 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. 

January 30, 2020, 04:14 

#10  
Member
Join Date: Jan 2020
Posts: 31
Rep Power: 3 
Quote:
in the links I send you my Mesh, My output Data and my article I am working on! my last Target is to simulate the blade displacement! http://s7.picofile.com/file/83865613..._yeki.msh.html http://s6.picofile.com/file/8386561326/data2D.out.html http://s7.picofile.com/file/83865613...rials.pdf.html 

January 30, 2020, 04:21 

#11 
Member
Join Date: Jan 2020
Posts: 31
Rep Power: 3 
yeah! this writes the F_UDMI(f, t, 0) by zero, I am really Tired by this! can I have Conversation with you in private! I will send you my article I am working on it! maybe you can help me... this is more than 3 month I am working on this UDF


January 30, 2020, 05:42 
Not working part

#12 
Senior Member

Which part of the UDF is not working. About writing I know it will not work but the solution is simple; just do writing within the loop, i.e., move the line with command fprintf before the end_f_loop. Is there any other issue with it?
__________________
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. 

January 30, 2020, 07:53 

#13  
Member
Join Date: Jan 2020
Posts: 31
Rep Power: 3 
Quote:
how can I make a grid motion to simulating the blade displacement?! with use of the function in the picture: yt is yold in my code and Phi is F_UDMI(f, t, 0) 

January 30, 2020, 08:49 
Define_grid_motion

#14 
Senior Member

Look for DEFINE_GRID_MOTION example in UDF manual
__________________
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. 

January 30, 2020, 11:36 

#15 
Member
Join Date: Jan 2020
Posts: 31
Rep Power: 3 

January 31, 2020, 03:18 
Use UDM

#16 
Senior Member

For all those variables that are varying with space, i.e., functions of their position, it is recommended to use UDM. It appears that yold is also a function of position. Therefore, you should invoke another UDM, and use F_UDMI(f,t,1) to store the value and then use same UDM in GRID_MOTION
__________________
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 
udf fluent displacement 
Thread Tools  Search this Thread 
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
UDF for vapor pressure  anuarun  Fluent UDF and Scheme Programming  9  March 3, 2021 08:16 
Replicating Scalable Wall Function with a UDF  yousefaz  FLUENT  0  August 4, 2017 02:30 
UDF in Fluent  Andrew  Fluent UDF and Scheme Programming  5  March 7, 2016 03:38 
Displacement of particles with an udf  Michael Heim  FLUENT  0  July 6, 2004 14:08 
UDF, UDF, UDF, UDF  Luc SEMINEL  Main CFD Forum  0  November 25, 2002 04:01 