CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   FLUENT (http://www.cfd-online.com/Forums/fluent/)
-   -   Problem accessing Temp. Gradient . . . (http://www.cfd-online.com/Forums/fluent/32685-problem-accessing-temp-gradient.html)

Satish December 9, 2003 19:43

Problem accessing Temp. Gradient . . .
 
Hi

I have a problem accessing the temperature gradient in a UDF.

I have a heat flux acting on the walls.I am writing using DEFINE_PROFILE. My bc is a function of temperature gradient.

In the tutorials, they gave the macro as C_T_G(c,t)[0].

but when i try to use this it is giving me a error. I even set the "solve/set/expert ", but i could not get it.

Can anyone help me in this

Thanks Satish

The path of it is --> \Fluent.Inc\fluent6.1.22\help\html\udf\node107.htm

ccc December 10, 2003 04:10

Re: Problem accessing Temp. Gradient . . .
 
hi Satish,

Did you use a coupled solver?

good luck.

ap December 10, 2003 16:21

Re: Problem accessing Temp. Gradient . . .
 
Which kind of error do you obtain?

Do you check gradients definition before using the macro. See the utilities section of UDF manual for that.

Hi :)

ap

Satish December 10, 2003 18:56

Re: Problem accessing Temp. Gradient . . .
 
I am not getting even with coupled solver.

The error is : Error: 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: ()

Thanks Satish

ap December 11, 2003 13:59

Re: Problem accessing Temp. Gradient . . .
 
Nothing to do with the solver. Your problem is that gradients are not defined on the first iteration, so it's impossible to read them.

Insert this line

if (!Data_Valid_P()) return;

before accessing gradients and answer YES to the question "Keep memory solver from being freed?" which will be asked you if you type the command /solve/set/expert.

Hi :)

ap

Satish December 11, 2003 17:54

Re: Problem accessing Temp. Gradient . . .
 
Thanks for ur help, now i am able to compile but gives a error when running.

i am giving a sample prog. ofcourse my profile is very big eqn. i am also applying flux on the walls.

even this is not working, i also tried with complied udf.

can u help me . . .

#include "udf.h"

DEFINE_PROFILE(test_profile1, t, i)

{ real x[ND_ND];

cell_t c;

begin_c_loop(c, t)

{

if (!Data_Valid_P()) return;

F_PROFILE(c, t, i) = (1.1*C_T_G(c,t)[0]);

} end_c_loop(c, t)

}

Andrew Garrard December 12, 2003 05:48

Re: Problem accessing Temp. Gradient . . .
 
Are you hooking this profile into a boundary such as a wall. If you are then I think you want to be using a face loop rather than a cell loop. If you applying a source term to a flow domain then you can use a DEFINE_SOURCE macro. What is it that you are trying to achieve?

Satish December 12, 2003 12:32

Re: Problem accessing Temp. Gradient . . .
 
Thanks for ur reply. Well i am hooking it up. for my model i have a heat flux. This should generate the C_T_G(c,t)[0] term.

I also have a udf for heat flux. its working. In the given udf below i wanna set the wall shear (Specified Shear)as follows

DEFINE_PROFILE(shear_profile,t,i)

{

real term1,term2;

cell_t c;

begin_c_loop (c,t)

term1 = 5*C_R(c,t)*sqrt(2*M_PI*UNIVERSAL_GAS_CONSTANT*C_T( c,t)/28.0134)/16;

term2 = (3.*0.0000185)/(4.*C_R(c,t)*C_T(c,t));

if (!Data_Valid_P()) return;

F_PROFILE(c,t1,i) = term1*(C_U(c,t)+term2*C_T_G(c,t)[0]);

end_c_loop(c,t1)

}

In this when i remove the gradient term it is successfully running. Can u help me out in this . . .

Thanks

Satish

ap December 12, 2003 15:47

Re: Problem accessing Temp. Gradient . . .
 
As said by Andrew Garrard, if you want to loop over a boundary, replace the begin_c_loop with a begin_f_loop (same for the end_c_loop).
Also, you should use F_ macros instead of C_ macros.
If you need to have access to cells value of some variable, you can retrieve the cell corresponding to the current face using F_C0(face, thread) macro.

Here there is an example of DEFINE_PROFILE on a wall.


DEFINE_PROFILE (wall_profile, t, position)
{
face_t f;
cell_t c0;
Thread *t0 = t->t0 /* t0 -> cell thread */
real rho;

begin_f_loop(f,t)
{
c0 = F_C0(f,t);

...

rho = C_R(c0,t0); /*Read density in the cell: use c0 and t0 to access cell values, use f and t for face value*/
F_PROFILE(f,t,position) = /*your profile function*/
}
end_f_loop{f,t,position}
}



P.S.
There seems to be some error in your code, maybe due to cut and paste: you start looping on cells with thread t and end the loop with the thread t1:

begin_c_loop (c,t)
...
end_c_loop(c,t1)

Also in the F_PROFILE you use t1 instead of t.

Hi :)

ap

Satish December 12, 2003 17:30

Re: Problem accessing Temp. Gradient . . .
 
Hi i am sorry, but the pointer line gives me error. THe line Thread *t0 = t->t0 is giving error like "structure reference not implemented". My udf is

DEFINE_PROFILE(shear_profile,t,i) {

real term1,term2,slip,rho;

real vel,tc,tp,dt,den,dtdxw;

cell_t c,c0;

face_t f;

Thread *t0 = t->t0;

if (!Data_Valid_P()) return;

begin_f_loop (f,t)

c0 = F_C0(f,t);

vel = F_U(f,t);

tc = F_T(f,t);

if (!Data_Valid_P()) return;

dtdxw = C_T_G(c0,t0)[0];

rho = 28.0134*F_P(f,t)/(F_T(f,t)* UNIVERSAL_GAS_CONSTANT);

if(tc <= 0.)

{

term1 = 0.;

}

else

{

term1 = 5*rho*sqrt(2*M_PI*UNIVERSAL_GAS_CONSTANT*F_T(f,t)/28.0134)/16;

}

term2 = 0;

if(rho == 0. || tc == 0.)

{

term2 = 0.;

}

else

{

term2 = (3.*0.0000185)/(4.*rho*tc);

}

slip = term1*(vel+dtdxw*term2);

F_PROFILE(f,t,i) = slip;

end_f_loop(f,t)

}

Any help w'd be appreciated...

Thanks

Satish

ap December 13, 2003 08:54

Re: Problem accessing Temp. Gradient . . .
 
You're trying to use this UDF as interpreted, but you have to compile it.

I succesfully compiled your udf (I just had to put the first { on a new line, because it gave me an error message).

If you're using FLUENT 6.1, compiling the UDF is really easy. If you work under Windows, you need Microsoft Visual C++, while under Linux you already have the C compiler.

1) Put the source file in the same directory of the case file.

2) Go to Define->User-Defined->Functions->Compiled

3) Click on Add and look for your source file

4) Click on Build

5) Click on Load

Use your UDF as usual.

Under FLUENT 6.0 it's a bit more difficult, but the manual contains the step by step procedure.

Hi :)

ap

Satish December 13, 2003 16:46

Re: Problem accessing Temp. Gradient . . .
 
Hi

Thanks for ur valuble reply, now i am able to compile it but when initializing the prob, it is giving the same error.

Thank u very much

Satish

ap December 15, 2003 09:03

Re: Problem accessing Temp. Gradient . . .
 
Are you using a user defined initialization function?

If you use UDM or UDS, make sure to properly set them in FLUENT.

Hi :)

ap

Satish December 15, 2003 13:58

Re: Problem accessing Temp. Gradient . . .
 
Hi

I am not using any UDS or UDM or Init function. I just need to set the profile to the walls. mine is a pressure inlet and pressure outlet. with flux acting on walls and i need to set the shear profile on the walls.

Thanks

Satish

ap December 15, 2003 17:03

Re: Problem accessing Temp. Gradient . . .
 
Ok. Try this function. I tested it and it works. I just added a check to see if gradient have been stored. If so, it does calculations, else it gives a null profile.

I tested it putting a "Message("Working")" command in the first if, and it gives a null profile during first iteration, then it properly calculates.


if (NULL != THREAD_STORAGE(t0,SV_T_G))
{
//code
}
else
{
//Profile = 0
}



The complete function is the following:


#include "udf.h"

DEFINE_PROFILE(shear_profile,t,i)
{

real term1,term2,slip,rho;
real vel,tc,tp,dt,den,dtdxw;
cell_t c,c0;
face_t f;
Thread *t0 = t->t0;

if (!Data_Valid_P()) return;

begin_f_loop (f,t)
{

if (NULL != THREAD_STORAGE(t0,SV_T_G))
{

c0 = F_C0(f,t);
vel = F_U(f,t);
tc = F_T(f,t);
dtdxw = C_T_G(c0,t0)[0];

rho = 28.0134*F_P(f,t)/(F_T(f,t)* UNIVERSAL_GAS_CONSTANT);
if(tc <= 0.)
{
term1 = 0.;
}
else
{
term1 = 5*rho*sqrt(2*M_PI*UNIVERSAL_GAS_CONSTANT*F_T(f,t)/28.0134)/16;
}

term2 = 0;

if(rho == 0. || tc == 0.)
{
term2 = 0.;
}
else
{
term2 = (3.*0.0000185)/(4.*rho*tc);
}
F_PROFILE(f,t,i) = term1*(vel+dtdxw*term2);
}
else
{
F_PROFILE(f,t,i) = 0.; }
}
end_f_loop(f,t)

}



P.S. The check on negative temperature can be avoided. FLUENT uses Kelvin, so T >= 0 always.

Hope it works.

Hi :)

ap

Satish December 16, 2003 14:42

Re: Problem accessing Temp. Gradient . . .
 
Hi,

Thank you very much...I got it. . .

Thanks

Satish

ap December 16, 2003 14:44

Re: Problem accessing Temp. Gradient . . .
 
You're welcome.

ap


All times are GMT -4. The time now is 19:43.