CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   scalar and its derivative (https://www.cfd-online.com/Forums/main/15080-scalar-its-derivative.html)

sucker April 15, 2008 11:59

scalar and its derivative
 
Hi all, I'm facing a problem and I couldn't find a way out. I'm trying to define an analytical scalar field (x*y) on a 2d rectangular geometery, and to get its first derivative. I found a UDF in Fluent Documetation which calculates the 4th power of temperature and its derivative and also stores them in UDS-0 and UDS-1. Actually this is very close to what I want. Therefore I took the UDF and modified it for my purpose. However it doesn't work fine. Below is the UDF I modified.(I havent change the name of the variables form the originals.) When I run a case with this UDF and export the cell center values, I see that the values of UDS-0 does not match the x*y. On the other hand, when I set the value of UDS-0 to a real number (e.g. 10.0) it takes the UDS-0 as 10 (which is correct) but it also calculates the magnitude of its derivative different than zero (it has to be zero because of the constant scalar field).

Any help is deeply appreciated.

#include "udf.h"

/* Define which user-defined scalars to use. */ enum { T4, MAG_GRAD_T4, N_REQUIRED_UDS };

DEFINE_ADJUST(adjust_fcn, domain) { Thread *t; cell_t c; face_t f; real z[ND_ND]; real y; real x; real T;

/* Make sure there are enough user-defined scalars. */ if (n_uds < N_REQUIRED_UDS)

Internal_Error("not enough user-defined scalars allocated");

/* Fill first UDS with temperature raised to fourth power. */ thread_loop_c (t,domain)

{

if (NULL != THREAD_STORAGE(t,SV_UDS_I(T4)))

{

begin_c_loop (c,t)

{

C_CENTROID(z,c,t);

y=z[1];

x=z[0];

C_UDSI(c,t,T4) = x*y;

}

end_c_loop (c,t)

}

}

thread_loop_f (t,domain)

{

if (NULL != THREAD_STORAGE(t,SV_UDS_I(T4)))

{

begin_f_loop (f,t)

{

F_CENTROID(z,f,t);

y=z[1];

x=z[0];

T = 0.;

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

T = x*y;

else if (NULL != THREAD_STORAGE(t->t0,SV_T))

T = x*y;

F_UDSI(f,t,T4) = x*y;

}

end_f_loop (f,t)

}

}

/* Fill second UDS with magnitude of gradient. */ thread_loop_c (t,domain)

{

if (NULL != THREAD_STORAGE(t,SV_UDS_I(T4)) &&

NULL != T_STORAGE_R_NV(t,SV_UDSI_G(T4)))

{

begin_c_loop (c,t)

{

C_UDSI(c,t,MAG_GRAD_T4) = NV_MAG(C_UDSI_G(c,t,T4));

}

end_c_loop (c,t)

}

}

thread_loop_f (t,domain)

{

if (NULL != THREAD_STORAGE(t,SV_UDS_I(T4)) &&

NULL != T_STORAGE_R_NV(t->t0,SV_UDSI_G(T4)))

{

begin_f_loop (f,t)

{

F_UDSI(f,t,MAG_GRAD_T4) = C_UDSI(F_C0(f,t),t->t0,MAG_GRAD_T4);

}

end_f_loop (f,t)

}

} }

sucker April 15, 2008 13:28

I fixed the problem, thanks!
 
I am sorry that I posted my message on the wrong forum. I should have posted it on the Fluent Forum. Anyway I fixed my problem.


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