CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   FLUENT (http://www.cfd-online.com/Forums/fluent/)
-   -   UDF problems (http://www.cfd-online.com/Forums/fluent/37557-udf-problems.html)

Winnie August 12, 2005 11:55

UDF problems
 
Hi,

I am trying to calculate the intersection angle between the velocity and the gradient of the temperature using UDF. My short code is as follows:

#include "udf.h"

DEFINE_ADJUST(Angle,domain)

{ Thread *thread; cell_t c; float TX,TY,TZ,TG; float U,V,W,Vel;

thread_loop_c(thread,domain)

{

begin_c_loop(c, thread)

{

TX = C_T_G(c,thread)[0];

TY = C_T_G(c,thread)[1];

TZ = C_T_G(c,thread)[2];

TG = sqrt(pow(TX,2.0)+pow(TY,2.0)+pow(TZ,2.0));

U = C_U(c,thread);

V = C_V(c,thread);

W = C_W(c,thread);

Vel = sqrt(pow(U,2.0)+pow(V,2.0)+pow(W,2.0));

C_UDMI(c,thread,0) = acos((U*TX+V*TY+W*TZ)/TG/Vel);

}

end_c_loop(c, thread)

} }

The compile was good but when I calculated for several iterations and tried to plot the result, the values are zero everywhere.

Can anyone please please help me with this program or give me some advice?

Thank you so much.

I am nearly exhausted by this problem.

Winnie

pUl| August 12, 2005 12:09

Re: UDF problems
 
hmm, they (fluent) recommend running some ScalarReconstruction routine to allocate memory internally when calculating the gradients of volume fraction. I'm not sure whether this is applicable to temperature gradients as well but it is worth a try. If you have access to the OTS, please check solution 982 to see what I mean.

Winnie August 12, 2005 12:32

Re: UDF problems
 
Thank you!

Forgive my ignorance, what is OTS?

Winnie

pUl| August 12, 2005 12:33

Re: UDF problems
 
Online Technical Support (http://clarify.fluent.com/eSupport)

Winnie August 12, 2005 12:47

Re: UDF problems
 
Thanks.

I tried the reconstruction gradient and it still doesn't work.

I don't have an account of OTS since I am a student. Can you provide more information?

Thanks again.

Winnie

pUl| August 12, 2005 12:48

Re: UDF problems
 
Here is an example:

#include "udf.h"
#define CON 1

DEFINE_ADJUST(store_gradient, domain)
{
Thread *t;
Thread **pt;
cell_t c;
int phase_domain_index = 0.;
Domain *pDomain = DOMAIN_SUB_DOMAIN(domain,phase_domain_index);
{
Alloc_Storage_Vars(pDomain,SV_VOF_RG,SV_VOF_G,SV_N ULL);
Scalar_Reconstruction(pDomain, SV_VOF,-1,SV_VOF_RG,NULL);
Scalar_Derivatives(pDomain,SV_VOF,-1,SV_VOF_G,SV_VOF_RG,
Vof_Deriv_Accumulate);
}


mp_thread_loop_c (t,domain,pt)
if (FLUID_THREAD_P(t))
{
Thread *ppt = pt[phase_domain_index];

begin_c_loop (c,t)
{
C_UDMI(c,t,0) = C_VOF_G(c,ppt)[0];
}
end_c_loop (c,t)
}
Free_Storage_Vars(pDomain,SV_VOF_RG,SV_VOF_G,SV_NU LL);
}

dirk August 12, 2005 12:55

Re: UDF problems
 
The temperature gradient is not stored by default. In the TUI go to "solve set expert" and disable "keep temporary solver memory from being freed". Then you should be able to use temperature gradients.

Dirk

Winnie August 12, 2005 12:57

Re: UDF problems
 
Hi,

Thanks a lot!

I think this case is quite more complex than mine since I am working on single phase flow.

I have got a converged solution for my problem, but I need know the intersection angle, therefore, I used UDF. I allocate a user defined memory, and compiles this code into FLUENT.

Is DEFINE_ADJUST macro used right?

Can you give me some other advices other than the method I used?

Thank you.

Winnie

pUl| August 12, 2005 13:00

Re: UDF problems
 
Try what dirk says first.

When you use the UDF, are you also hooking up the adjust function to the solver?

Winnie August 12, 2005 13:03

Re: UDF problems
 
Do you mean 'disable'?

I checked it, it is 'no'.

Any more suggestions?

Thank you

Winnie

dirk August 12, 2005 13:08

Re: UDF problems
 
Sorry, it has to be "enable", so you have to set it to "yes".


Winnie August 12, 2005 13:10

Re: UDF problems
 
No, it didn't work.

I didn't change the default set in FLUENT. I think adjust function is not hookedto the solver.

Winnie

Winnie August 12, 2005 13:12

Re: UDF problems
 
I tried both. But it didn't work.

What does that mean? If I disabled it, then the temperature gradient will not be calcualted by solver?

Thanks.

Winnie

dirk August 12, 2005 13:19

Re: UDF problems
 
The temperature gradient is calculated but you can only access it while energy equation is solved. If you let Fluent store the gradients with the command I told then you can access the gradients at any time. But you have to make at least one iteration after you set that command and then execute your UDF. It should work then in my opinion.

Dirk

Winnie August 12, 2005 13:44

Re: UDF problems
 
Thanks, dirk

I have tried. And still can not solve the problem.

What do you think of my code? Do you think it is OK for calculating the intersection angle between the velocity and the temperature gradient?

Thank you for the help.

Winnie

dirk August 12, 2005 17:03

Re: UDF problems
 
I just tried your UDF. It seems to work as I get non zero values for UDM 0. By the way, what is the physical sense of this intersection angle ?

Firas August 13, 2005 04:53

UDF problems
 
Hi iam just starting with UDF i used unsteady BC for velocity inlet that mentioned in manual i stored the file at C:\ when asking program to cpompile the file he cant read first line #include "udf.h" the qustion should i have cpp compiler to do calaculation and if not what to do. Best regards

Firas August 13, 2005 05:33

Re: UDF problems
 
dear all when i run on of the manual example i have the following at line 1 that is include udf.h should i have c++ or what to do. thanks

cpp -IC:\FLUENT.INC\fluent6.0/src -IC:\FLUENT.INC\fluent6.0/cortex/src -IC:\FLUENT.INC\fluent6.0/client/src -IC:\FLUENT.INC\fluent6.0/multiport/src -I. -DUDFCONFIG_H="<udfconfig.h>" unsteadyError: unsteady: line 1: parse error.

Winnie August 14, 2005 06:29

Re: UDF problems
 
I am trying to do the optomization to enhance the convective heat transfer. And lower this angle, the better the heat transfer rate.

I still can't get the code work in my case, can you please tell me the detailed procedure you did? And does it have any relationship with the mesh? my mesh is irregular.

Thank you. dirk.

Winnie

dirk August 16, 2005 07:47

Re: UDF problems
 
I took your file, hooked it as interpreted UDF, enabled the storage of the gradients, set the UDF as an adjust function, set the number of UDM to 1 and iterated. Maybe you should define it as an execute-on-demand, so it doesn't have to be executed after every iteration.


All times are GMT -4. The time now is 06:33.