CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   THREAD-ID in UDF (https://www.cfd-online.com/Forums/fluent-udf/86178-thread-id-udf.html)

truffaldino March 16, 2011 09:19

THREAD-ID in UDF
 
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;




Amir March 16, 2011 09:37

Hi,
for simple debugging, would you use a Message command to check whether it enters a if statement or not?

truffaldino March 16, 2011 09:57

Quote:

Originally Posted by Amir (Post 299673)
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 March 16, 2011 10:03

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 March 16, 2011 10:20

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)

Amir March 16, 2011 10:52

Quote:

Originally Posted by truffaldino (Post 299685)
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 !

truffaldino March 16, 2011 11:13

Quote:

Originally Posted by Amir (Post 299696)
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"

Amir March 16, 2011 12:38

Quote:

Originally Posted by truffaldino (Post 299705)
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?

truffaldino March 16, 2011 14:29

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 March 16, 2011 17:39

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".

Amir March 17, 2011 08:57

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?

natantyt April 3, 2012 18:36

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 (Post 299667)
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 April 4, 2012 04:15

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 April 4, 2012 04:19

Quote:

Originally Posted by Amir (Post 299862)
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

Kanarya December 3, 2012 07:51

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)
}



}

zwbmimi March 5, 2013 13:36

Hi, I also have this problem and fix it by using the ID provided by FLUENT, which can be found in BC panel.

Kanarya March 6, 2013 04:31

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 (Post 411754)
Hi, I also have this problem and fix it by using the ID provided by FLUENT, which can be found in BC panel.


zwbmimi March 6, 2013 04:39

Yes, my UDF works in parallel.


Quote:

Originally Posted by Kanarya (Post 411883)
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


Kanarya March 6, 2013 04:45

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 (Post 411887)
Yes, my UDF works in parallel.


zwbmimi March 6, 2013 04:59

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 (Post 411888)
for what kind of application are you using it?
can you help me to make it parallel?

thanks in advance...


Kanarya March 6, 2013 05:04

thanks. no it is not working in parallel. what do you mean with thread ID?
I am using this one like ID "if( THREAD_ID(mixture_thread) == 4 )"
and it works in serial perfect but not in parallel.

thanks
Quote:

Originally Posted by zwbmimi (Post 411890)
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.


Kanarya March 6, 2013 05:08

are you using auto-partitioning or manual one?
thanks...
Quote:

Originally Posted by Kanarya (Post 411894)
thanks. no it is not working in parallel. what do you mean with thread ID?
I am using this one like ID "if( THREAD_ID(mixture_thread) == 4 )"
and it works in serial perfect but not in parallel.

thanks


zwbmimi March 6, 2013 05:15

Hi Kanarya,

My code is like this,
DEFINE_SOURCE(source_1,c,t,dS,eqn)
{
int aaa = 4;

...

if (THREAD_ID(t) == aaa)
{
...
}
}
where t is the thread passed by FLUENT UDF Marco.

Quote:

Originally Posted by Kanarya (Post 411897)
are you using auto-partitioning or manual one?
thanks...


Kanarya March 6, 2013 05:29

are you using auto-partitioning or manual one?
thanks...

Quote:

Originally Posted by zwbmimi (Post 411901)
Hi Kanarya,

My code is like this,
DEFINE_SOURCE(source_1,c,t,dS,eqn)
{
int aaa = 4;

...

if (THREAD_ID(t) == aaa)
{
...
}
}
where t is the thread passed by FLUENT UDF Marco.


zwbmimi March 6, 2013 05:34

Hi Kanarya,

Do you mean define the zones in geometry? Actually, my geometry has many zones. I define them when I drawn it.

Quote:

Originally Posted by Kanarya (Post 411908)
are you using auto-partitioning or manual one?
thanks...


Kanarya March 6, 2013 05:43

No. You parallelise it when you start the Fluent or after starting it.
Quote:

Originally Posted by zwbmimi (Post 411914)
Hi Kanarya,

Do you mean define the zones in geometry? Actually, my geometry has many zones. I define them when I drawn it.


zwbmimi March 6, 2013 05:52

It should be auto partitioning.

Quote:

Originally Posted by Kanarya (Post 411919)
No. You parallelise it when you start the Fluent or after starting it.


Kanarya March 6, 2013 07:11

thanks a lot..I will try to deal with this!!

BEst regards...
Quote:

Originally Posted by zwbmimi (Post 411923)
It should be auto partitioning.


Bharadwaj B S February 19, 2015 00:54

Regarding ZONE ID in ICEM CFD!!!!!
 
Quote:

Originally Posted by truffaldino (Post 353052)
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

Hi everyone,

I am getting ACCESS VIOLATION ERROR, when I Initialize my case (WITH AN UDF FOR MASS FLUX).

This error, as I have came across is because of using a parameter which is not present or given in FLUENT (my case F_T(f, t) i.e, face temperature).

In my case I have used t = Lookup_Thread(d, ID). I have taken the ID from FLUENT BOUNDARY CONDITION PANEL. And my mesh was generated using ICEM CFD.

QUESTION:

How do you find out the ZONE ID in ICEM CFD????

I really have very less idea regarding GAMBIT.
Any help is of great use. Thanks in advance.:)

Bharadwaj

pakk February 19, 2015 04:09

Your problem is that the Fluent UDF tries to read face temperatures that don't exist.

Why do you want to find the zone id in ICEM CFD???

(That is like saying: "I have a problem with my car, it will not start. How do I get the serial number of my telephone?")

Bharadwaj B S February 19, 2015 05:04

Solved
 
Quote:

Originally Posted by pakk (Post 532454)
Your problem is that the Fluent UDF tries to read face temperatures that don't exist.

Why do you want to find the zone id in ICEM CFD???

(That is like saying: "I have a problem with my car, it will not start. How do I get the serial number of my telephone?")

Hi pakk,

First of all sorry for confusing. I was confused.

Thanks for your genuine and speedy reply, I was writing a UDF for mass flux from a sphere surface, which is present inside a flow domain.

I was able to write the same. (Thankfully). Just before few minutes ago.

Actually I have used F_T(f, t) as a variable in my flux logic. i.e,
flx = a * F_T(f, t);
where a is just a arbitrary constant.

Its a practice problem which I am doing in order to get grip in writing UDF.

And yes if I use the ZONE ID from FLUENT Boundary conditions tab. I was not able to hook the UDF to the specific sphere.

I opened the mesh in ICEM, while saving the output file in output tab, I gave the required ZONE ID(my case 13). And then I exported the mesh to fluent using Write/output.

Again thanks for your suggestion. I had not switched on the "energy equation", which was giving me an error during initialization. I switched on the energy equation and initialized with BC's (without hooking UDF). Once the case was initialized I hooked the UDF and got the result. Hurray.

hazari.aaquib December 15, 2015 08:19

Dear All,,

I am facing the exact same problem (as previously mentioned, by Truffaldino) with my UDF where the statement if(Thread_ID==...) is ignored in the program.

I have to modify the specific dissipation rate at the interface of a stratified two phase channel flow.
The zone according to fluent is 2 for the interface.

Here is my UDF

# include "udf.h"
DEFINE_ADJUST(adjust_omega, mixture_domain)
{
real xc[ND_ND];
real abcd = 5;
cell_t c;
int ID = 2;
Thread *thread = Lookup_Thread(mixture_domain, ID);
thread_loop_c(thread, mixture_domain)
{
begin_c_loop(c, thread)
{
C_CENTROID(xc, c, thread);
if (THREAD_ID(thread) == ID)
{
C_O(c, thread) = 2927;
}
}
end_c_loop(c, thread)
}

}

According to the previous posts on this thread Truffaldino, solved the same problem (if(Thread_ID)==...) by finding out that gambit had a different values for zone ID than fluent.
I have used ANSYS meshing.

Any suggestions will be appreciated.

zwbmimi December 15, 2015 21:24

Quote:

Originally Posted by hazari.aaquib (Post 577651)
Dear All,,

I am facing the exact same problem (as previously mentioned, by Truffaldino) with my UDF where the statement if(Thread_ID==...) is ignored in the program.

I have to modify the specific dissipation rate at the interface of a stratified two phase channel flow.
The zone according to fluent is 2 for the interface.

Here is my UDF

# include "udf.h"
DEFINE_ADJUST(adjust_omega, mixture_domain)
{
real xc[ND_ND];
real abcd = 5;
cell_t c;
int ID = 2;
Thread *thread = Lookup_Thread(mixture_domain, ID);
thread_loop_c(thread, mixture_domain)
{
begin_c_loop(c, thread)
{
C_CENTROID(xc, c, thread);
if (THREAD_ID(thread) == ID)
{
C_O(c, thread) = 2927;
}
}
end_c_loop(c, thread)
}

}

According to the previous posts on this thread Truffaldino, solved the same problem (if(Thread_ID)==...) by finding out that gambit had a different values for zone ID than fluent.
I have used ANSYS meshing.

Any suggestions will be appreciated.


I think you may use the ID shown in Fluent. It can be found in the Boundary Condition Panel.

hazari.aaquib December 16, 2015 06:17

Hi zwbmimi,

I have used the fluent ID from the boundary conditions panel and even then the commands under if(THREAD_ID==...) is ignored.

Is there any other way?


All times are GMT -4. The time now is 07:27.