Compile UDF for Fluent
I need to include Lorentz force equation as a source term in my model. how can i compile a UDF and use it in fluent ?
|
Use the DEFINE_SOURCE macro for specifying a custom source term (ensure the units are of the form generation rate per volume, e.g. kg/m^3/s for the continuity equation), there are a couple of examples in the UDF manual to get you started (ask back here if you get stuck). As for compiling UDFs, see the reply in your duplicate thread.
|
respected sir,
could suggest me what mistake i do in this code as given below ? #include "udf.h" #define mu 1.26*(10e-6) #define I 300 #define reff 0.008 #define r 0.005 /*-------------------------------------------------------- Momentum source term in x ----------------------------------------------------------*/ DEFINE_SOURCE(xmom_source,c,t,dS,eqn) { float x[ND_ND], source; face_t f; F_CENTROID (x,f,t); source =-((mu*I*I)/(4*3.14*3.14*reff*reff*r)) * (exp (-r*r / (2*reff*reff))) * (1-(exp (-r*r / (2*reff*reff)))) * pow((1-(x[1]/t),2) * (x[0]/r); dS[eqn] = 0; return source; } /*-------------------------------------------------------- Momentum source term in y ----------------------------------------------------------*/ DEFINE_SOURCE(ymom_source,c,t,dS,eqn) { float x[ND_ND], source; face_t f; F_CENTROID (x,f,t); source = -((mu*I*I)/(4*3.14*3.14*r*r)) * pow((1-(exp (-r*r / (2*reff*reff)))),2) * (1-(x[1]/t)); dS[eqn] = 0; return source; } /* HEAT INPUT CODE */ DEFINE_PROFILE(Gauss,t,i) { real x[ND_ND], c[ND_ND]; face_t f; real r; r = 0.0035; begin_f_loop(f, t) { F_CENTROID (x,f,t); F_PROFILE (f,t,i) = (3*(300*14*0.7) / (3.14*pow(r,2))) * exp (-3*(x[0]*x[0])/ pow(r,2)); } end_f_loop(f,t) } |
For starters, use a trailing dot for real numbers (otherwise the compiler will read them as integers), for example:
Code:
F_PROFILE (f,t,i) = (3.*(300.*14.*0.7) / (3.14*pow(r,2))) * exp (-3.*(x[0]*x[0])/ pow(r,2)); |
i have modified the format with trailing dot as suggested. the UDF is given below and it gives the error: Line 27: invalid type for binary expression: float / pointer to structure.
how can i rectify the error in the following udf ? /*------ HEAT FLUX -------- */ #include "udf.h" DEFINE_PROFILE(Gauss,t,i) { real x[ND_ND], c[ND_ND]; face_t f; real r; r = 0.005; begin_f_loop(f, t) { F_CENTROID (x,f,t); F_PROFILE (f,t,i) = (3.*(300.*14.*0.7/0.001) / (3.14*pow(r,2.))) * exp (-3.*(x[0]*x[0])/ pow(r,2.)); } end_f_loop(f,t) } /*--------- Lorentz Force ----------*/ /*-------- x momentum source ------*/ #DEFINE mu 0.00000126; #DEFINE I 300.; #DEFINE reff 0.006; #DEFINE r 0.005; DEFINE_SOURCE(xmom,c,t,dS,eqn) { real x[ND_ND]; real mu, I, reff, r, source; C_CENTROID(x,c,t); source = -((mu*I*I)/(4.*3.14*3.14*reff*reff*r)) * (exp (-r*r / (2.*reff*reff))) * (1.-(exp (-r*r / (2.*reff*reff)))) * pow((1.-(x[1]/t),2.) * (x[0]/r)); dS[eqn]=0; return source; } /* ----------- y momentum source ------------*/ DEFINE_SOURCE(ymom,c,t,dS,eqn) { real x[ND_ND]; real source; C_CENTROID(x,c,t); source = -((mu*I*I)/(4.*3.14*3.14*r*r*c)) * pow((1.-(exp (-r*r / (2.*reff*reff)))),2.) * (1.-(x[1]/t)); dS[eqn]=0; return source; } |
One of your problems is here:
Code:
#DEFINE mu 0.00000126; Code:
real 0.00000126;, 300.;, 0.006;, 0.005;, source; Code:
#DEFINE I 300. Option 2: don't use #DEFINE: Code:
real mu=0.00000126, I=300, ... |
All times are GMT -4. The time now is 14:06. |