CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (http://www.cfd-online.com/Forums/fluent-udf/)
-   -   something wrong when compiling udf, however the code is correct when interpreting (http://www.cfd-online.com/Forums/fluent-udf/117015-something-wrong-when-compiling-udf-however-code-correct-when-interpreting.html)

richard ben April 30, 2013 10:59

something wrong when compiling udf, however the code is correct when interpreting
 
Hey, everyone,

I began to change my udf from interpet to compile, however meet some problem and have no idea how to do.

1. The diffusivity

the code:

DEFINE_DIFFUSIVITY(uds_diffusivity_2,c,t,i)
{
return s_lamda*(1.0-POR)/3.0;
}
when I load this code, the uds goes to divergence. However, when I change "s_lamda*(1.0-POR)/3.0" into a constant, it works fine. In fact, s_lamda*(1.0-POR)/3.0 is a constant in my code since I defined "s_lamda" and "POR" in the begining of the code. This is weird

2. The source term

the code:
DEFINE_SOURCE(fluid_source_1,c,t,dS,eqn)
{
real Re, P, alamda_f, h,source_f;
alamda_f=C_K_L(c,t);
Re=C_U(c,t)/POR*ds*C_R(c,t)/C_MU_L(c,t);
P=-8.278*pow(POR,0.38)+57.384*pow(POR,1.38)-106.63*pow(POR,2.38)+95.756*pow(POR,3.38)-37.24*pow(POR,4.38);
h=2.096*pow(POR,0.38)*alamda_f*pow(Re,0.438)*P/(ds*ds);
source_f=h*(C_UDSI(c,t,0)-C_T(c,t));
dS[eqn]=-h;
return source_f;
}

I can load this source without any problem when interpreting, however in compiling it doesn't work at all. And the error is:
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: #f

I have no idea what's wrong with my code or is there any difference between compile and interpret?

I will appreciate a lot for your help.

blackmask April 30, 2013 11:14

You could use "THREAD_STORAGE" as the keyword to search in the fluent udf manual. You have tried to access the pointers before the spaces they associated to are allocated.

richard ben April 30, 2013 21:31

Thank you very much for your reply. I didn't get you. I can load this source term in interpreted UDFs. And when I load it in compiled UDFs, I have two UDSs. And I can display C_UDSI(c,t,0) but just cannot load this source term.

richard ben April 30, 2013 22:13

hey blackmask,

I know the reason but still have no idea how to solve it.
the problem locates in this code : alamda_f=C_K_L(c,t)
when I change C_K_L(c,t) into a constant, it works fine.
So the problem is I can't cite using C_K_L(c,t) ? Why?
Do you have any ideas? Or this is the problem you mentioned.
Access it without allocated?

blackmask April 30, 2013 22:40

Give it a try.

Quote:

Originally Posted by richard ben (Post 424223)
2. The source term

the code:
DEFINE_SOURCE(fluid_source_1,c,t,dS,eqn)
{
real Re, P, alamda_f, h,source_f;

if (!Data_Valid_P())
return;


alamda_f=C_K_L(c,t);
Re=C_U(c,t)/POR*ds*C_R(c,t)/C_MU_L(c,t);
P=-8.278*pow(POR,0.38)+57.384*pow(POR,1.38)-106.63*pow(POR,2.38)+95.756*pow(POR,3.38)-37.24*pow(POR,4.38);
h=2.096*pow(POR,0.38)*alamda_f*pow(Re,0.438)*P/(ds*ds);
source_f=h*(C_UDSI(c,t,0)-C_T(c,t));
dS[eqn]=-h;
return source_f;
}




richard ben May 1, 2013 04:27

hey blackmask,

thank you for your suggestion. it didn't work. however i solved this problem by setting the thermal conductivity into a picewise-polynomial function related to the temperature. if the thermal conductivity is set to be a constant then it didn't work and the same error. i don't know why but it is solved.

however i met another problem. do you know what is the meaning of this code?
Thread *t0=thread-t0;
when i compiled the udfs the warnings are:
'initializing' : 'struct thread_struct *' differs in levels of indirection from 'int '
local variable 't0' used without having been initialized

although i can ignore these two wranings, when i load this udf containing this code
it doesn't work. so i check the code one by one, and found that this code might be the problem.
but have no idea how to intialize 't0'

do you have any ideas? i will appreciat a lot for your help.

blackmask May 1, 2013 06:02

Could it be thread_t0? This line can only be understood in context.

richard ben May 11, 2013 07:36

thank you for your help and sorry for the delayed reply.
This code is copied in the UDF manual Charpter 8.2.5.2.
I assumed it was wrong and thought it should be Thread *t0=thread
Is it ok?


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