CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   How accessing derivatives in UDF (https://www.cfd-online.com/Forums/fluent/32310-how-accessing-derivatives-udf.html)

Pietro Asinari October 13, 2003 05:50

How accessing derivatives in UDF
 
Hello everybody,

I'm writing a source terms by UDFs which need to access temperature derivatives C_T_G[i]. I have prevented the solver from freeing gradient data (solve/set/expert). In the code, I have inserted a control to verify the availability of gradient data:

if(!Data_Valid_P()) { source = 0; return source; }

The calculation works well and I save the results. When I try to load the DAT file, Fluent crashes for "Access Violation". It looks like "Data_Valid_P()" doesn't work.

What's the matter ?

Thank you in advance,

Pietro

ap October 13, 2003 07:17

Re: How accessing derivatives in UDF
 
You say the calculation works well, so Data_Valid_P() works, because it allows you to do the first iteration without errors when you try to access to gradients.

It's difficult to tell why this happens without looking to the code.

Do you use user defined memories or scalars?

Does the problems happens also when you load .cas and .dat files together?

Hi :)

ap

Pietro Asinari October 13, 2003 08:30

Re: How accessing derivatives in UDF
 
If I do some iterations without the source terms modelled by UDFs and then I turn on them, the calculation works well because temperature gradients have been correctly calculated. Saving the calculation, my UDFs are automatically linked to CASE file.

Restarting Fluent, the error occurs because temperature gradients are not stored into DATA file. The function "Data_Valid_P()" probably verifies the loading of DATA file but not what there is in. The starting check doesn't find temperature gradients into DATA file and crashes.

That's the code:

DEFINE_SOURCE(source_continuity, c, t, dS, eqn) {

/* ... code ... */

dT_dx_P = C_T_G(c,t)[0];

dT_dr_P = C_T_G(c,t)[1];

source=cost*sqrt(dT_dx_P*dT_dr_P);

return source; }

How can I add temperature gradients to DATA file ?

Thanks a lot,

Pietro


Ale October 13, 2003 09:13

Re: How accessing derivatives in UDF
 
Hi!

Try to add this control:

if (NULL != THREAD_STORAGE(t,SV_T_G))

{

....

} else

{

source=0.0;

}

I hope this helps. Regards,

Ale

Pietro Asinari October 13, 2003 11:30

Re: How accessing derivatives in UDF
 
Thank you very much, Ale !!

You have solved my troubles. The control you suggest works very well.

Regards,

Pietro


All times are GMT -4. The time now is 00:11.