CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   UDF problem (ACCESS VIOLATION) (https://www.cfd-online.com/Forums/fluent/50839-udf-problem-access-violation.html)

Jorge Poyatos March 11, 2009 13:57

UDF problem (ACCESS VIOLATION)
 
Hi! sorry , but i am having some problems with a UDF, I am using it for discrete phase model. I can interpret it without problems but when i try to display the particles track i get the next error:

FLUENT received fatal signal (ACCESS VIOLATION) 1. Note exact evets leading to error 2. Save case/data under new name 3. Exit program and restart to continue. 4. Report error to your distributor. Error Object: ()

The UDF is as follows:

#include "udf.h"

#include "mem.h"

DEFINE_DPM_DRAG(particle_drag_force,Re,p)

{

cell_t c;

Thread *t;

real drag_force;

double cd,epsilon,lkolm,pinelli;

epsilon = C_D(c, t);

if (Re > 1000)

{

cd=0.44;

}

else

{cd=24*(1+0.15*pow(Re,0.687))/Re;

}

lkolm = pow(0.001003/998.2,3);

lkolm = pow(lkolm/epsilon,0.25);

pinelli = 16.0*lkolm/0.000421-1.0;

pinelli = (exp(pinelli)-exp(-pinelli))/(exp(pinelli)+exp(-pinelli)); /* calculate TANH */

pinelli = 0.4*pinelli+0.6;

cd=cd/pow(pinelli,2.0);

drag_force = 18*cd*Re/24 ;

return (drag_force);

}

I realized that when I change: epsilon = C_D(c, t); by: epsilon = 10000 or any constant value.

Everything goes right.

if someone cuold help me.

R Liew March 12, 2009 03:39

Re: UDF problem (ACCESS VIOLATION)
 
Hi,

I assume your problem is unsteady in time, so I think the problem is the first iteration. You should iterate one time without using the UDF. Then, when this first iteration is done, you can turn on the UDF and then it should work. This is because Fluent need to calculate the diffusivity first.

You can make a if-function in the DEFINE loop like this:

real timestep = RP_Get_Real('physical_timestep');

real current_time = RP_Get_Real('current_time');

if (current_time>timestep)

{ your code }

else

{ drag_force = 0; }

Good luck!

R Liew

Jorge Poyatos March 12, 2009 08:25

Re: UDF problem (ACCESS VIOLATION)
 
It doesn't work. I think there is a problem in the function when a use Thread and cell, could you please check it? should I include c,t as arguments?

Thank you!

R Liew March 12, 2009 11:54

Re: UDF problem (ACCESS VIOLATION)
 
You should try this. If it's not working, you should check the UDF manual.

#include "udf.h"

#include "mem.h"

DEFINE_DPM_DRAG(particle_drag_force,Re,p)

{

cell_t c;

Thread *t;

real drag_force;

real timestep = RP_Get_Real('physical_timestep');

real current_time = RP_Get_Real('current_time');

if (current_time>timestep)

{

double cd,epsilon,lkolm,pinelli;

epsilon = C_D(c, t);

if (Re > 1000)

{cd=0.44;}

else

{cd=24*(1+0.15*pow(Re,0.687))/Re;}

lkolm = pow(0.001003/998.2,3);

lkolm = pow(lkolm/epsilon,0.25);

pinelli = 16.0*lkolm/0.000421-1.0;

pinelli = (exp(pinelli)-exp(-pinelli))/(exp(pinelli)+exp(-pinelli)); /* calculate TANH */

pinelli = 0.4*pinelli+0.6;

cd=cd/pow(pinelli,2.0);

drag_force = 18*cd*Re/24 ;

}

else

{

drag_force = 0;

}

return (drag_force);

}

hervé March 12, 2009 12:13

Re: UDF problem (ACCESS VIOLATION)
 
I am not experienced with interpreted udf, but should not you use "real" (which is a fluent type) instead of "double"?

"real" as the benefit to be immediately adpated either to float or double depending on the fluent version you are running, without having to recompile your udf.

Could this be the problem? Frankly I don't know...

HenrikS March 16, 2009 08:02

c and t are not passed as arguments to the macro and you need to supply these. Change:

cell_t c;
Thread *t;

to

cell_t c = P_CELL(p);
Thread *t = P_CELL_THREAD(p);

and things should hopefully work!

/Henrik


All times are GMT -4. The time now is 22:59.