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: 29 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; 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*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: 2,948 Blog Entries: 1 Rep Power: 31 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 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 how can I do?
#3
New Member

Join Date: Jan 2020
Posts: 29
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: 2,948 Blog Entries: 1 Rep Power: 31 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 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:45 #5
New Member

Join Date: Jan 2020
Posts: 29
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: 2,948 Blog Entries: 1 Rep Power: 31 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 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, 09:07 #7
New Member

Join Date: Jan 2020
Posts: 29
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;
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*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,476 Rep Power: 21 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; 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*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...tml#post612025   January 30, 2020, 04:45 Segmentation Violation Expected #9 Senior Member   Vinerm Join Date: Jun 2009 Location: Nederland Posts: 2,948 Blog Entries: 1 Rep Power: 31 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 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, 05:14 #10
New Member

Join Date: Jan 2020
Posts: 29
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; 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*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: 29 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: 2,948 Blog Entries: 1 Rep Power: 31 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 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, 08:53 #13
New Member

Join Date: Jan 2020
Posts: 29
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: 2,948 Blog Entries: 1 Rep Power: 31 Look for DEFINE_GRID_MOTION example in UDF manual 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.   January 30, 2020, 12:36 #15
New Member

Join Date: Jan 2020
Posts: 29
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: 2,948 Blog Entries: 1 Rep Power: 31 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 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 Show Printable Version Email this Page Search this Thread: Advanced Search Display Modes Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 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 OffTrackbacks are Off Pingbacks are On Refbacks are On Forum Rules Similar Threads Thread Thread Starter Forum Replies Last Post anuarun Fluent UDF and Scheme Programming 8 July 14, 2020 14:02 yousefaz FLUENT 0 August 4, 2017 03:30 Andrew Fluent UDF and Scheme Programming 5 March 7, 2016 04:38 Michael Heim FLUENT 0 July 6, 2004 15:08 Luc SEMINEL Main CFD Forum 0 November 25, 2002 05:01

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