CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (http://www.cfd-online.com/Forums/fluent-udf/)
-   -   Get gradient from uds (http://www.cfd-online.com/Forums/fluent-udf/81333-get-gradient-uds.html)

qwerty753 October 24, 2010 05:59

Get gradient from uds
 
I defined an uds.
As postprocessing fluent allows to read the uds variable by contour etc.
I just want to reat the gradient of my variable for a surface integral or a plot.
How can i get it?
Thank you

dmoroian October 25, 2010 01:50

Check the UDF Manual at 3.2.3 Cell Macros (to see when and how you make available the gradients to your udf), and after that try the macro C_UDSI_G.

qwerty753 October 25, 2010 06:31

Thank you for your help!
I wrote this udf:
# include "udf.h"
# define domain_ID 2
DEFINE_ON_DEMAND(store_gradient)
{
Domain *domain;
cell_t c;
Thread *t;

domain=Get_Domain(1);

/* Fill the UDM with magnitude of gradient. */
thread_loop_c (t,domain)
{
begin_c_loop (c,t)
{
C_UDMI(c,t,0) = C_UDSI_G(c,t,0)[1];
}
end_c_loop (c,t)
}

This doesn't work becouse if i execute on demand i receive this message:
FLUENT received fatal signal (ACCESS_VIOLATION)
1. Note exact events leading to error.
2. Save case/data under new name.
3. Exit program and restart to continue.
4. Report error to your distributor.
Error Object: ()
Indeed if i wrote:

DEFINE_ON_DEMAND(store_gradient)
{
Domain *domain;
cell_t c;
Thread *t;

domain=Get_Domain(1);

/* Fill the UDM with magnitude of gradient. */
thread_loop_c (t,domain)
{
begin_c_loop (c,t)
{
C_UDMI(c,t,0) = C_UDSI(c,t,0);
}
end_c_loop (c,t)
}

to check if it run...i have no problem, why?

dmoroian October 25, 2010 07:25

As I said previously :
Quote:

Check the UDF Manual at 3.2.3 Cell Macros (to see when and how you make available the gradients to your udf), and after that try the macro C_UDSI_G.
I'll give you a hint: the memory for the gradient is not allocated when you try to access C_UDSI_G, so look for the gradient paragraph in the above section of the manual!

qwerty753 October 25, 2010 07:33

OK i understood my error...

solve/set/expert and then answering yes to the question Keep temporary solver memory from being freed?


i set correctly and now it runs.

But i discover that the gradient is calcolated by uds at cell... i need at face because i'm at B.C..

Is there any procedure?

dmoroian October 25, 2010 11:38

If you use second order discretisation scheme, then the gradient is constant over the entire cell, so you may use the cell value on the boundary face.
Otherwise, just as wild guess try F_UDSI_G.

mila_oliv July 27, 2012 13:52

hey qwerty753,

did you solve your problem?
I need the gradient too, but it's inserted in my function, so i dont need to postprocess the gradient directly...

look what i've done:

Quote:

#include "udf.h"
DEFINE_ON_DEMAND(heat_flux_lines)
{
Domain *d;
Thread *t;
cell_t c;
real H;
real rho,u,Temp,k,dTdx;
d=Get_Domain(1);
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
rho=C_R(c,t);
u=C_U(c,t);
Temp=C_T(c,t);
k=C_K_L(c,t);
dTdx=C_T_G(c,t)[0];
H+=((rho*u*Temp)-(k*dTdx))*0.1;
C_UDMI(c,t,1)=H;
}
end_c_loop(c,t)
}
}


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