CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   FLUENT (http://www.cfd-online.com/Forums/fluent/)
-   -   UDF Help (http://www.cfd-online.com/Forums/fluent/32130-udf-help.html)

chiph September 14, 2003 00:44

UDF Help
 
I have a problem about UDF. Which is including macros of DEFINE_ADJUST and DEFINE_PROFILE, and the profile of velocity is ok, but when I hooks the DEFINE_ADJUST macro (which I want to print out some data)there has an error message;

Iterating... iter continuity x-velocity y-velocity time/iter

Error: FLUENT received fatal signal (ACCESS_VIOLATION) 1. Note exact events 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: ()

#include "udf.h" Thread *thread;

DEFINE_ADJUST(my_adjust, d) { real x[ND_ND], y;

face_t f;

float u;

float h = 0.02;

begin_f_loop(f, thread)

{

F_CENTROID(x,f,thread);

y = x[1];

u = 100.0*y*(h-y);

}

end_f_loop(f,thread)

printf("y= %5f ; u= %5f\n", y,u); printf("End of Adjust "); }

DEFINE_PROFILE(x_vel, thread, position) {

real x[ND_ND], y;

face_t f;

float u;

float h = 0.02;

begin_f_loop(f, thread)

{

F_CENTROID(x,f,thread);

y = x[1];

u = 100.0*y*(h-y);

F_PROFILE(f,thread,position) = u;

}

end_f_loop(f,thread) }

ap September 14, 2003 07:57

Re: UDF Help
 
I think you should solve your problem putting this line

if (!Data_Valid_P()) return;

just before the

begin_f_loop(f, thread)

in your DEFINE_ADJUST function. This allows FLUENT to check if all variables you are accessing are defined, avoiding access violations.

Hi

ap

chiph September 14, 2003 08:25

Re: UDF Help
 
Hi, ap;

Thanks for your help. I try with your suggestion, but it still have the same error message. Do you have another comment?

chiph

ap September 14, 2003 09:07

Re: UDF Help
 
I checked your code and tried it on a case file of mine. Now it runs, but I don't know if it works properly because I'm not sure which data you need to print out.

I made these changes:

- Added the thread_loop_f(thread, d) loop, which is what solves the problem of access violation. DEFINE_ADJUST works on the domain d, but you have to retrieve threads using a command like this. I don't know if you need it, but there is the equivalent macro for cells: thread_loop_c(thread, d).

- Moved the declaration of *thread in the DEFINE_ADJUST function. DEFINE_PROFILE doesn't need it, so it's better to define it locally.

- Substituted all float variables with real one. Real is an internal data type of FLUENT which stands for float or double, in dependence of which solver you run. Use real and your code will work with both single and double precision solvers.

I commented my changes in the code: try it and keep me up to date :)


#include "udf.h"


DEFINE_ADJUST(my_adjust, d)
{
Thread *thread; /* I moved this here */
real x[ND_ND], y;
face_t f;
real u;
real h = 0.02;


if (!Data_Valid_P()) return; /* I added this */
thread_loop_f(thread, d) /* I added this: loops over all face threads in a domain*/
{
begin_f_loop(f, thread)
{
F_CENTROID(x,f,thread);
y = x[1];
u = 100.0*y*(h-y);
}
end_f_loop(f,thread)
}
printf("y= %5f ; u= %5f\n", y,u);
printf("End of Adjust ");
}

DEFINE_PROFILE(x_vel, thread, position)
{
real x[ND_ND], y;
face_t f;

real u;
real h = 0.02;

begin_f_loop(f, thread)
{
F_CENTROID(x,f,thread);
y = x[1];
u = 100.0*y*(h-y);

F_PROFILE(f,thread,position) = u;
}
end_f_loop(f,thread)
}




Hope this works

Hi :)

ap


All times are GMT -4. The time now is 13:15.