CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   can any one correct this(udf) (https://www.cfd-online.com/Forums/fluent/46685-can-any-one-correct-udf.html)

solomon November 28, 2007 03:50

can any one correct this(udf)
 
hello

i writting an position based udf like source=5(x*x)*(y*y) here x and y are the position of grids .i tried like this and iam new to c programming.so kinly help me to do this

thank you

#include "udf.h"

DEFINE_SOURCE(cure_source,c,t,ds,eqn) {

real source; cell_t c; Thread *t; real xc[ND_ND];

/* loop over all cells */

begin_c_loop_all(c,t)

{

C_CENTROID(xc,c,t);

source=8*C_CENTROID(xc,c,t)*C_CENTROID(xc,c,t);

}

end_c_loop_all(c,t)

return source; }

mohanraj December 1, 2007 10:06

Re: can any one correct this(udf)
 
#include "udf.h" DEFINE_SOURCE(cure_source,c,t,ds,eqn) { real source; real xc[ND_ND]; C_CENTROID(xc,c,t); /* Returns centroid in xc[ND_ND] for cell in thread t */ /* xc[0] = x distance, xc[1] = y distance */ source=5.0*xc[0]*xc[0]*xc[1]*xc[1]; ds[eqn]=0.0; return source; }

solomon December 3, 2007 22:34

Re: can any one correct this(udf)
 
thank you

solomon December 3, 2007 22:38

Re: can any one correct this(udf)
 
thank you mohan again i trapped in to another udf,it is hooked well but when i give iterare it shows fattel error,the udf goes like this

#include"udf.h" #include <mem.h> #include"math.h" #include"complex.h"

DEFINE_SOURCE(heat_gen,cell,thread,ds,eqn) { real x[ND_ND]; real source; real ko,E,R,Qalpha;

C_CENTROID(x, cell, thread);

ko=1.0;

E=53830.0;

R=8.341;

Qalpha=2000000.0;

source=C_R(cell,thread)*Qalpha*ko*exp(-E/(R*C_T(cell,thread)));

ds[eqn]=0;

return source; } pleaese give some sujjestions

mohanraj December 4, 2007 12:02

Re: can any one correct this(udf)
 
Hi,

Do you need to have "math.h" and "complex.h"? Instead of complex.h you can use a data structure. For example,

typedef struct cmpx { double x; double y; } complex;

complex z;

z.x="real" z.y="imaginary"

This should work. But, I don't see any error in the code.

Can u pls. check the following step?

1. Go to the fluent case file directory and invoke fluent 2. load the .cas and .dat file, initialize 3. unload the library namely, "libudf" (define->user-define->function->manage) 4. complie your source term udf again 5. load and hook the UDF in your scalar equation.

then you try running.

Other way is you can activate the species transport and reaction. Include your custom reaction in DEFINE_VR_RATE(...). This should definitely work.


solomon December 5, 2007 01:24

Re: can any one correct this(udf)
 
hello

i am new to this udf writing,but other udf like boiling etc hooked well and running.i think the complex.h and math.h is nessesary because there is a funtion called exp(...) used. any way i will try it

thank you


All times are GMT -4. The time now is 19:28.