CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Compile UDF for Fluent (https://www.cfd-online.com/Forums/fluent-udf/165573-compile-udf-fluent.html)

kcgmech January 20, 2016 09:31

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 ?

`e` January 20, 2016 16:03

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.

kcgmech January 21, 2016 11:42

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)
}

`e` January 21, 2016 17:48

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));
Next, be specific. Show us any errors and explain what result you're expecting compared to what you're actually achieving.

kcgmech January 29, 2016 05:46

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;
}

pakk January 29, 2016 08:29

One of your problems is here:

Code:

#DEFINE mu 0.00000126;
#DEFINE I 300.;
#DEFINE reff 0.006;
#DEFINE r 0.005;
...
real mu, I, reff, r, source;

"#DEFINE mu 0.00000126;" means: everywhere where you write "mu", the compiler should read "0.00000126;". So the last line that I copied becomes:
Code:

real 0.00000126;, 300.;, 0.006;, 0.005;, source;
This not what you want. You should choose. Option 1: use #define in the right way:
Code:

#DEFINE I 300.
Note: no ; after the number! And don't try to redefine I as real.

Option 2: don't use #DEFINE:
Code:

real mu=0.00000126, I=300, ...
There may be other problems.


All times are GMT -4. The time now is 14:06.