CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Main CFD Forum

scalar and its derivative

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   April 15, 2008, 11:59
Default scalar and its derivative
  #1
sucker
Guest
 
Posts: n/a
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)

}

} }
  Reply With Quote

Old   April 15, 2008, 13:28
Default I fixed the problem, thanks!
  #2
sucker
Guest
 
Posts: n/a
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.
  Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



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