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

 January 29, 2020, 03:12 UDF for blade displacement #1 New Member   Join Date: Jan 2020 Posts: 21 Rep Power: 2 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 = 1-sin(((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.69e-6; real teta=1.38e-9; 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.0e0-zety*zety); //----------------------------------- real ts=CURRENT_TIMESTEP; real time=CURRENT_TIME; //----------------------------------- real Ay,By,y; 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; //----------------------------------- //----------------------------------- 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, 08:01 Phi is a scalar #2 Senior Member     Vinerm Join Date: Jun 2009 Location: Nederland Posts: 539 Rep Power: 16 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. etedalgara likes this. __________________ Regards, Vinerm PMs only for private content

January 29, 2020, 08:07
how can I do?
#3
New Member

Join Date: Jan 2020
Posts: 21
Rep Power: 2
Quote:
 Originally Posted by vinerm 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.
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, 08:10 Suggestions #4 Senior Member     Vinerm Join Date: Jun 2009 Location: Nederland Posts: 539 Rep Power: 16 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. etedalgara likes this. __________________ Regards, Vinerm PMs only for private content

January 29, 2020, 08:45
#5
New Member

Join Date: Jan 2020
Posts: 21
Rep Power: 2
Quote:
 Originally Posted by vinerm 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.
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, 08:49 Write inside the loop #6 Senior Member     Vinerm Join Date: Jun 2009 Location: Nederland Posts: 539 Rep Power: 16 Since Phi is not a single value, you have write your output file within the face loop. And as usual, replace Phi with UDM. etedalgara likes this. __________________ Regards, Vinerm PMs only for private content

January 29, 2020, 09:07
#7
New Member

Join Date: Jan 2020
Posts: 21
Rep Power: 2
Quote:
 Originally Posted by vinerm Since Phi is not a single value, you have write your output file within the face loop. And as usual, replace Phi with UDM.
my apologies ...
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);
face_t f;

begin_f_loop(f,t)
{
F_CENTROID(x,f,t);
yy=x[0];
F_UDMI(f, t, 0) = 1-sin(((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.69e-6;
real teta=1.38e-9;
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.0e0-zety*zety);
//-----------------------------------
real ts=CURRENT_TIMESTEP;
real time=CURRENT_TIME;
//-----------------------------------
real Ay,By,y;
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;
//-----------------------------------

//-----------------------------------
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, 03:08 #8 Senior Member   Alexander Join Date: Apr 2013 Posts: 1,169 Rep Power: 18 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.69e-6; real teta=1.38e-9; 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.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-sin(((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=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"); fprintf(fout," %f %f %f %f %f\n",time,yold,Fy,vold,F_UDMI(f, t, 0)); fclose(fout); #endif /* !RP_NODE */ }``` etedalgara likes this. __________________ best regards ****************************** press LIKE if this message helped you How to ask questions: https://www.cfd-online.com/Forums/si...ml#post6120255

 January 30, 2020, 04:45 Segmentation Violation Expected #9 Senior Member     Vinerm Join Date: Jun 2009 Location: Nederland Posts: 539 Rep Power: 16 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. etedalgara likes this. __________________ Regards, Vinerm PMs only for private content

January 30, 2020, 05:14
#10
New Member

Join Date: Jan 2020
Posts: 21
Rep Power: 2
Quote:
 Originally Posted by AlexanderZ 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.69e-6; real teta=1.38e-9; 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.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-sin(((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=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"); fprintf(fout," %f %f %f %f %f\n",time,yold,Fy,vold,F_UDMI(f, t, 0)); fclose(fout); #endif /* !RP_NODE */ }```
Thank you ... a problem acquired! for *F_UDMI(f, t, 0)* this write 0!
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, 05:21 #11 New Member   Join Date: Jan 2020 Posts: 21 Rep Power: 2 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, 06:42 Not working part #12 Senior Member     Vinerm Join Date: Jun 2009 Location: Nederland Posts: 539 Rep Power: 16 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? etedalgara likes this. __________________ Regards, Vinerm PMs only for private content

January 30, 2020, 08:53
#13
New Member

Join Date: Jan 2020
Posts: 21
Rep Power: 2
Quote:
 Originally Posted by vinerm 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?
thank you my friend, the problem loop over x solved!
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, 09:49 Define_grid_motion #14 Senior Member     Vinerm Join Date: Jun 2009 Location: Nederland Posts: 539 Rep Power: 16 Look for DEFINE_GRID_MOTION example in UDF manual etedalgara likes this. __________________ Regards, Vinerm PMs only for private content

January 30, 2020, 12:36
#15
New Member

Join Date: Jan 2020
Posts: 21
Rep Power: 2
Quote:
 Originally Posted by vinerm Look for DEFINE_GRID_MOTION example in UDF manual
thanks ... there is just one question, how can I use *yold* in the *DEFINE_EXECUTE_AT_END* macro to use it in *Grid motion* macro?

 January 31, 2020, 04:18 Use UDM #16 Senior Member     Vinerm Join Date: Jun 2009 Location: Nederland Posts: 539 Rep Power: 16 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 etedalgara likes this. __________________ Regards, Vinerm PMs only for private content

 Tags udf fluent displacement