CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Wrote my first udf but nothing happens (https://www.cfd-online.com/Forums/fluent-udf/104683-wrote-my-first-udf-but-nothing-happens.html)

 diamondx July 12, 2012 23:07

Wrote my first udf but nothing happens

Hello everyone,
I started learning UDF today, i created my first code. It's an easy source term that i apply on a SPECIFIC domain of fluid. the source is a x-momentum, here is my code:
Quote:
 #include "udf.h" DEFINE_SOURCE(test,c,t,dS,eqn) { real xc[ND_ND]; real source; C_CENTROID(xc,c,t); if ((xc[0] == -0.135608)&&(xc[1] == 0.179728)) {source = 1000; dS[eqn] = 0;} else {source = 0;dS[eqn] = 0;} C_UDMI(c,t,0)=source; return source; }
The UDF is interpreted/compiled without any error. this udf applies a source in the location(x,y). I should see a change in the velocity vector, right ? nothing happens, why ? I'm trying to simulate plsma actuators and in all the article that i read, this same udf code is used...

 flotus1 July 13, 2012 04:44

Because of numerical inaccuracies, you always have to provide a small threshold for statements like "if (position != ..."
The position of the cells in your domain will never be -0.135608, but rather -0.135608000001

Make it "if(position < x_0+threshold && position > x_0-threshold)" instead

 diamondx July 13, 2012 09:12

thanks alexander for you reply. went back and change the code into this one:
Quote:
 #include "udf.h" DEFINE_SOURCE(test,c,t,dS,eqn) { real xc[ND_ND]; real source; C_CENTROID(xc,c,t); if ((xc[0] <= -0.1557860000)&&(xc[0] >= -0.196412000000)&&(xc[1] <= 0.189188000000)&&(xc[1] >= 0.168735000000)) {source = 1000000; dS[eqn] = 0;} else {source = 0;dS[eqn] = 0;} return source; }
Still the problem persist... if you are wondering where did i get those coordinates, i went to draw the mesh, and i used mouse probe to to determine the location where i want the source to be applied. i copy paste it in the code...

 flotus1 July 13, 2012 09:44

Are you 100% sure that there are cell centroids within the ranges you specified?
Remember that sources are applied on a "per-cell" basis.

For debugging purposes, try applying the source to a bigger area with less restrictions, say

if (xc[0] < 0) source= 1000;
return source;

If this still has no effect... well we will have to think again.

 diamondx July 13, 2012 10:48

thanks a lot for your support, recently compilation works but i soon as i hit on run calculation it shows me this error i dont know why:

Quote:
 999999 (..\src\mpsystem.c@1149): mpt_read: failed: errno = 10054 999999: mpt_read: error: read failed trying to read 8 bytes: No such file or directory MPI Application rank 0 exited before MPI_Finalize() with status -1073741819 The Parallel FLUENT process could not be started.

 flotus1 July 13, 2012 10:53

Are you running in parallel?

Normal UDFs do not work in parallel, but as far as I understood, they can be changed accordingly. Refer to the UDF manual.

For now, try running on 1 core only.

 diamondx July 13, 2012 11:04

changed into serial, still error problem.
Error:
1. Note exact events leading to error.
2. Save case/data under new name.
3. Exit program and restart to continue.
Error Object: #f

Yeah this is definitely the coordinates.
Quote:
 #include "udf.h" DEFINE_SOURCE(test,c,t,dS,eqn) { real xc[ND_ND]; real source,y; C_CENTROID(xc,c,t); y=xc[1]; if (y <= 0.1864891) {source = 1000000; dS[eqn] = 0;} else {source = 0;dS[eqn] = 0;} C_UDMI(c,t,0)=source; return source;
if you were me, how will you get the coordinates, will you use the mouse probe ?
the procedure: i load the case, define then interpret the udf. i go to cell condition turn on source term , aplly x-momentum click on ok. then initialize and finally run calculation...

 flotus1 July 13, 2012 13:05

1 Attachment(s)
Here is a source UDF I currently use (stripped it from everything but the coordinate thing):
Copy it and try to run it.

DEFINE_SOURCE(sourceterm,c,t,dS,eqn)
{
double x[ND_ND];
double x0,y0;
double y_m=0.0;
double I_0=1000;

C_CENTROID(x,c,t);
if(x[1] <= y_m)
{
source = I_0;
}
}
return source;

When you say "apply x momentum" you mean you add 1 momentum source like in my attached picture?
The rest of your procedure seems ok.

 diamondx July 13, 2012 15:15

finally it worked. My udf was good. it worked after i changed the scenario. i was applying the source in a convergent divergent nozzle. velocity was near transonic, may be that's why nothing was happening. after i changed the geometry into a duct where air was flowing with 1 m/s. i could see the source in the velocity contour plot. thanks a lot for you support alex, you deserve a reputation up...

 kaushik_rai July 15, 2012 09:32

hi

how can we differentiate between a 32 & 64 bit udf in fluent???

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