thedal |
June 29, 2022 03:43 |
Density gradient UDF
I have written this code to get the Density gradient in a pressure-based solver by switching ON UDS for density. But it gives SIGSEGV error.
This is based on the UDF Example available in Fluent Manual for getting Temperature gradient. I changed it to Density. Since face values are not available for density, I interpolated and calculated it.
Code:
# include "udf.h"
DEFINE_ADJUST(adjust_gradient, domain)
{
Thread* t;
cell_t c;
face_t f;
/* Fill UDS with the variable. */
thread_loop_c(t, domain)
{
begin_c_loop(c, t)
{
C_UDSI(c, t, 0) = C_R(c, t);
}
end_c_loop(c, t)
}
thread_loop_f(t, domain)
{
if (THREAD_STORAGE(t, SV_UDS_I(0)) != NULL)
begin_f_loop(f, t)
{
F_UDSI(f, t, 0) = (C_R(F_C0(f, t), THREAD_T0(t)) + C_R(F_C1(f, t), THREAD_T1(t))) / 2;
}
end_f_loop(f, t)
}
}
DEFINE_SOURCE(gradient_source, c, t, dS, eqn)
{
real source;
source = C_UDSI_G(c, t, 0)[1];
dS[eqn] = 0;
return source;
}
|