CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

THREAD-ID in UDF

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 16, 2011, 10:19
Default THREAD-ID in UDF
  #1
Senior Member
 
truffaldino's Avatar
 
Join Date: Jan 2011
Posts: 249
Blog Entries: 5
Rep Power: 17
truffaldino is on a distinguished road
I would be grateful if someone could help me to fix the problem.

I am using THREAD_ID(t) in if statement to set different visosities in different zones. But it does not work in " if (Thread_ID(t)==...) " statement in my UDF. Whe I run fluent with this UDF, it does not distingush between zones.

It is a very simple code, what could be wrong here?:

PHP Code:

#include "udf.h"

#define xtop -1.
#define xbot 0.

#define rho 1.225
#define nu 1.4607E-5

#define C3 357.9

#define idtop 11
#define idbot 10

DEFINE_TURBULENT_VISCOSITY(mu_tct)
{

real mu;
real nut;
real xi;
real r[ND_ND];

C_CENTROID(r,c,t);

    if(
THREAD_ID(t)==idtop)
    {

            if(
r[0]>xtop)
            {

            
nut=C_NUT(c,t);
            
xi=nut/nu;
            
xi=xi*xi*xi;
            
mu=rho*nut*xi/(xi+C3);

            }
            else 
            {

            
mu=0;

            };

    };

    if(
THREAD_ID(t)==idbot)
    {

            if(
r[0]>xbot)
            {
        
            
nut=C_NUT(c,t);
            
xi=nut/nu;
            
xi=xi*xi*xi;
            
mu=rho*nut*xi/(xi+C3);

            }

            else
            {

            
mu=0;

            };

    };

return 
mu;


truffaldino is offline   Reply With Quote

Old   March 16, 2011, 10:37
Default
  #2
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 735
Blog Entries: 1
Rep Power: 23
Amir is on a distinguished road
Hi,
for simple debugging, would you use a Message command to check whether it enters a if statement or not?

Last edited by Amir; March 16, 2011 at 10:53.
Amir is offline   Reply With Quote

Old   March 16, 2011, 10:57
Default
  #3
Senior Member
 
truffaldino's Avatar
 
Join Date: Jan 2011
Posts: 249
Blog Entries: 5
Rep Power: 17
truffaldino is on a distinguished road
Quote:
Originally Posted by Amir View Post
Hi,
for simple debugging, would you use a Message command to check whether it enters a if statement or not?
I have checked it without message: I have just removed "if(THREAD_ID...) statements and everything works fine, as seen from postprocessing, except it chooses one viscousity function for all zones, so it does not enter "if(THREAD_ID...) statements
truffaldino is offline   Reply With Quote

Old   March 16, 2011, 11:03
Default
  #4
Senior Member
 
truffaldino's Avatar
 
Join Date: Jan 2011
Posts: 249
Blog Entries: 5
Rep Power: 17
truffaldino is on a distinguished road
I have checked it without message: I have just removed "if(THREAD_ID...) statements and everything works fine, as seen from postprocessing, except it chooses one viscousity function for all zones, so it does not enter "if(THREAD_ID...) statements
truffaldino is offline   Reply With Quote

Old   March 16, 2011, 11:20
Default
  #5
Senior Member
 
truffaldino's Avatar
 
Join Date: Jan 2011
Posts: 249
Blog Entries: 5
Rep Power: 17
truffaldino is on a distinguished road
And there is another strange thing: when I put "Message" or "Error" statement, interpretor says:

function "CX_Message" not founs (pc=80)

or

function "CX_Primitive_Error" not found (pc=80)
truffaldino is offline   Reply With Quote

Old   March 16, 2011, 11:52
Default
  #6
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 735
Blog Entries: 1
Rep Power: 23
Amir is on a distinguished road
Quote:
Originally Posted by truffaldino View Post
I have checked it without message: I have just removed "if(THREAD_ID...) statements and everything works fine, as seen from postprocessing, except it chooses one viscousity function for all zones, so it does not enter "if(THREAD_ID...) statements
just a suggestion:
do not introduce idtop & idbot as:
Code:
#define idtop 11
#define idbot 10
try in define macro:
Code:
int idtop=11
int idbot=10
it may help !
Amir is offline   Reply With Quote

Old   March 16, 2011, 12:13
Default
  #7
Senior Member
 
truffaldino's Avatar
 
Join Date: Jan 2011
Posts: 249
Blog Entries: 5
Rep Power: 17
truffaldino is on a distinguished road
Quote:
Originally Posted by Amir View Post
just a suggestion:
do not introduce idtop & idbot as:
Code:
#define idtop 11
#define idbot 10
try in define macro:
Code:
int idtop=11
int idbot=10
it may help !
Thanks Amir,

I have already tried this: it does not help. I am wanderin, could it be an interpretor problem, since it does not recognize commands like "Message" and "Error"
truffaldino is offline   Reply With Quote

Old   March 16, 2011, 13:38
Default
  #8
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 735
Blog Entries: 1
Rep Power: 23
Amir is on a distinguished road
Quote:
Originally Posted by truffaldino View Post
Thanks Amir,

I have already tried this: it does not help. I am wanderin, could it be an interpretor problem, since it does not recognize commands like "Message" and "Error"
you're right if you have such these problems with other UDFs with the same headers. is it the case?
Amir is offline   Reply With Quote

Old   March 16, 2011, 15:29
Default
  #9
Senior Member
 
truffaldino's Avatar
 
Join Date: Jan 2011
Posts: 249
Blog Entries: 5
Rep Power: 17
truffaldino is on a distinguished road
Thanks Amir,

I have tried with other udf Message and Error macros do not work, so there is something wrong with an interpretter indeed.
truffaldino is offline   Reply With Quote

Old   March 16, 2011, 18:39
Default
  #10
Senior Member
 
truffaldino's Avatar
 
Join Date: Jan 2011
Posts: 249
Blog Entries: 5
Rep Power: 17
truffaldino is on a distinguished road
I have solved the problem: it turns out that zone ID numbers must be taken as assigned by gambit (as in mesh file) and not as shown by fluent!

As for "Error" and "Message" makros they do not work, but can be replaced by "printf".
truffaldino is offline   Reply With Quote

Old   March 17, 2011, 09:57
Default
  #11
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 735
Blog Entries: 1
Rep Power: 23
Amir is on a distinguished road
really? I've used ID's that FLUENT shows for my UDFs before and they've worked.
would you please also checked that with other versions of FLUENT?
Amir is offline   Reply With Quote

Old   April 3, 2012, 19:36
Default
  #12
Member
 
Nathan
Join Date: Aug 2010
Posts: 62
Rep Power: 16
natantyt is on a distinguished road
Hi

I've got the same problem with my UDF to define different diffusivities for different zones , did you solve this? I appreciate your suggestions. Did you define the zone ID from boundary box or cell zone box?



Quote:
Originally Posted by truffaldino View Post
I would be grateful if someone could help me to fix the problem.

I am using THREAD_ID(t) in if statement to set different visosities in different zones. But it does not work in " if (Thread_ID(t)==...) " statement in my UDF. Whe I run fluent with this UDF, it does not distingush between zones.

It is a very simple code, what could be wrong here?:

PHP Code:
 
#include "udf.h"
 
#define xtop -1.
#define xbot 0.
 
#define rho 1.225
#define nu 1.4607E-5
 
#define C3 357.9
 
#define idtop 11
#define idbot 10
 
DEFINE_TURBULENT_VISCOSITY(mu_tct)
{
 
real mu;
real nut;
real xi;
real r[ND_ND];
 
C_CENTROID(r,c,t);
 
    if(
THREAD_ID(t)==idtop)
    {
 
            if(
r[0]>xtop)
            {
 
            
nut=C_NUT(c,t);
            
xi=nut/nu;
            
xi=xi*xi*xi;
            
mu=rho*nut*xi/(xi+C3);
 
            }
            else 
            {
 
            
mu=0;
 
            };
 
    };
 
    if(
THREAD_ID(t)==idbot)
    {
 
            if(
r[0]>xbot)
            {
 
            
nut=C_NUT(c,t);
            
xi=nut/nu;
            
xi=xi*xi*xi;
            
mu=rho*nut*xi/(xi+C3);
 
            }
 
            else
            {
 
            
mu=0;
 
            };
 
    };
 
return 
mu;
 

natantyt is offline   Reply With Quote

Old   April 4, 2012, 05:15
Default
  #13
Senior Member
 
truffaldino's Avatar
 
Join Date: Jan 2011
Posts: 249
Blog Entries: 5
Rep Power: 17
truffaldino is on a distinguished road
Hello Nathan,

Yes I have solved the problem but it was a long time ago: I remember that it turns out that zone ID numbers must be taken as assigned by gambit (as in mesh file) and not as shown by fluent! That is why my procedure was not working. So, in file I have presented above, it was necessary to change values of idtop and idbottom to those given by gambit in mesh file.

Truffaldino
truffaldino is offline   Reply With Quote

Old   April 4, 2012, 05:19
Default
  #14
Senior Member
 
truffaldino's Avatar
 
Join Date: Jan 2011
Posts: 249
Blog Entries: 5
Rep Power: 17
truffaldino is on a distinguished road
Quote:
Originally Posted by Amir View Post
really? I've used ID's that FLUENT shows for my UDFs before and they've worked.
would you please also checked that with other versions of FLUENT?
Hello Amir,

I was not aware of your messge, sorry for late responce. Unfortunately I have no access to different versions of Fluent, so I cannot check it.

Truffaldino
truffaldino is offline   Reply With Quote

Old   December 3, 2012, 08:51
Default
  #15
Senior Member
 
Join Date: May 2011
Posts: 231
Rep Power: 16
Kanarya is on a distinguished road
Hi, I have problem to save mass flow rate at outlet
I did following udf but it seems UDMI doesnt work because it is always zero.
is there anyone who can help me?

thanks in advance!
here is my code:
#include "udf.h"
DEFINE_EXECUTE_AT_END(measure_mass_flow)
{
real mass_flow;
Domain *d=Get_Domain(1);
cell_t c;
face_t f;
Thread *mixture_thread = Lookup_Thread(d,4);
Thread **pt = THREAD_SUB_THREADS(mixture_thread);
Thread *tp = pt[0];
Thread *ts = pt[1];

mass_flow=0.;

mp_thread_loop_f(mixture_thread,d,pt)

if( THREAD_ID(mixture_thread) == 4 )

{
begin_f_loop(f,mixture_thread)

{


F_UDMI(f,mixture_thread,0)+= F_FLUX(f,tp);


}
end_f_loop(f,mixture_thread)
}



}
Kanarya is offline   Reply With Quote

Old   March 5, 2013, 14:36
Default
  #16
New Member
 
W Z
Join Date: Nov 2010
Posts: 11
Rep Power: 15
zwbmimi is on a distinguished road
Hi, I also have this problem and fix it by using the ID provided by FLUENT, which can be found in BC panel.
zwbmimi is offline   Reply With Quote

Old   March 6, 2013, 05:31
Default
  #17
Senior Member
 
Join Date: May 2011
Posts: 231
Rep Power: 16
Kanarya is on a distinguished road
hi Zwbmimi,
thanks for the answer!

I did it as well. But now i have problem to use it in parallel.
Can you use it in parallel..?

best regards


Quote:
Originally Posted by zwbmimi View Post
Hi, I also have this problem and fix it by using the ID provided by FLUENT, which can be found in BC panel.
Kanarya is offline   Reply With Quote

Old   March 6, 2013, 05:39
Default
  #18
New Member
 
W Z
Join Date: Nov 2010
Posts: 11
Rep Power: 15
zwbmimi is on a distinguished road
Yes, my UDF works in parallel.


Quote:
Originally Posted by Kanarya View Post
hi Zwbmimi,
thanks for the answer!

I did it as well. But now i have problem to use it in parallel.
Can you use it in parallel..?

best regards
zwbmimi is offline   Reply With Quote

Old   March 6, 2013, 05:45
Default
  #19
Senior Member
 
Join Date: May 2011
Posts: 231
Rep Power: 16
Kanarya is on a distinguished road
for what kind of application are you using it?
can you help me to make it parallel?

thanks in advance...
Quote:
Originally Posted by zwbmimi View Post
Yes, my UDF works in parallel.
Kanarya is offline   Reply With Quote

Old   March 6, 2013, 05:59
Default
  #20
New Member
 
W Z
Join Date: Nov 2010
Posts: 11
Rep Power: 15
zwbmimi is on a distinguished road
Hi, i include the thread id in source terms of my uds. Does your code work well in parallel without the tread id? I'm happy to help.


Quote:
Originally Posted by Kanarya View Post
for what kind of application are you using it?
can you help me to make it parallel?

thanks in advance...
zwbmimi is offline   Reply With Quote

Reply


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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to access only one phase in multiphase model by UDF wersoe Fluent UDF and Scheme Programming 1 January 4, 2017 08:11
Parallelizing UDF Hattori Hanzo Fluent UDF and Scheme Programming 4 July 17, 2010 15:26
thread pointer comparison crash in Fluent UDF Miriam Main CFD Forum 0 August 31, 2008 17:40
Phase locked average in run time panara OpenFOAM 2 February 20, 2008 15:37
UDF: Checking Thread Storage Greg Perkins FLUENT 0 March 10, 2000 21:35


All times are GMT -4. The time now is 00:54.