CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   HEEELP!! Laplacian temperature (https://www.cfd-online.com/Forums/fluent-udf/139399-heeelp-laplacian-temperature.html)

stef_pasc July 23, 2014 09:24

HEEELP!! Laplacian temperature
 
Hi everyone!!
I'm trying to calculate the laplacian of temperature field in order to introduce it into the source terme of energy equation. Here there is a simplification of my C code.

DEFINE_ADJUST(adjust_gradient, domain)
{
Thread *t;
cell_t c;

if (! Data_Valid_P())
return;

thread_loop_c (t,domain)
{
begin_c_loop (c,t)
{
C_UDSI(c,t,0)=C_T_RG(c,t)[0];
C_UDSI(c,t,1)=C_T_RG(c,t)[1];
C_UDSI(c,t,2)=C_T_RG(c,t)[2];
}
end_c_loop (c,t)
}

}

DEFINE_SOURCE(energy_source,c,t,ds,eqn)
{

real source;

source=20*C_UDSI(c,t,0);

C_UDMI(c,t,0)=C_UDSI(c,t,0);
C_UDMI(c,t,1)=source;
C_UDMI(c,t,2)=C_UDSI_G(c,t,0)[0]; /*some calculus for testing the data*/
C_UDMI(c,t,3)=1/C_UDSI_G(c,t,0)[0];
C_UDMI(c,t,4)=100*C_UDSI_G(c,t,0)[0];

ds[eqn]=0;
return source;

}

The operations I make are:
Add User Scalars and memory
Inactivate UDS equations
Tape solver/set/expert---> yes for "keep temporary solver memory ...."
Launch the computation

SO I have 2 principal problems:
Sometimes, I receive a "segmentation fault" error message: this is due to the lines
C_UDSI(c,t,0)=C_T_G(c,t)[0];
C_UDSI(c,t,1)=C_T_G(c,t)[1];
C_UDSI(c,t,2)=C_T_G(c,t)[2];

If I use C_T(c,t), there's no more problems...whyyy??;
In this case, if I plot "Reconstruction dT/dx", Scalar 0 and Memory 0, they should coincide but there some little differences.

Is there someone who can help me, pleeease???:(:(

Thank you guys!!!
Stefano

blackmask July 24, 2014 22:09

To the first question, you need to ensure that the pointer is non-null before accessing it. You can disable your udf for first few iterations then enable it, or you can check the pointer of C_T_G in your udf.

To the second question, the UDSIs are governed by the convection-diffusion equation. For each iteration/time step, they are set with the value of temperature gradient but they will change according to their governing equations.

Dr Bill Wangard provided a solution for gradients calculation in this forum. You can search his threads for the solution.

stef_pasc August 5, 2014 04:29

Thank you blackmask for your answer!
I added an If statement with a condition on storage and it works. But I have a doubt. Indeed, if I try to verify iterations in the cells, and I found out that iterations are less than the real number of cells.
For example, I have 2048 cells while I got 1040 iterations. It means that UDS for some cells qre not allocated. How can I solve this? :confused:

Thank you very much for your help!!! :)

thread_loop_c (t,d)
{
if (NULL != THREAD_STORAGE(t,SV_UDS_I(0))&&
NULL != THREAD_STORAGE(t,SV_UDS_I(1))&&
NULL != THREAD_STORAGE(t,SV_UDS_I(2)))
{ k=0;
begin_c_loop (c,t)
{
C_UDSI(c,t,0)=C_T_G(c,t)[0];
C_UDSI(c,t,1)=C_T_G(c,t)[1];
C_UDSI(c,t,2)=C_T_G(c,t)[2];

k+=1;
printf("cell number%d \n", k);
}
end_c_loop (c,t)
}
}


All times are GMT -4. The time now is 02:23.