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/)
-   -   UDM just for fluid zone (https://www.cfd-online.com/Forums/fluent-udf/164965-udm-just-fluid-zone.html)

nima_nz January 6, 2016 11:05

UDM just for fluid zone
 
Hi
My domain includes both solid zone and fluid zone, but when I use
--------
thread_loop_c(t,domain)
{
begin_c_loop(c,t)
{.
----------
The UDF loops over all cells. How can I set it just for the fluid zone?
Thanks

nima_nz January 6, 2016 13:45

i have tried to use the following macro FLUID_THREAD_P(t) but it is giving an error message, saying structure reference not implemented.

`e` January 6, 2016 15:41

You can distinguish between cell zones using their threads. For example:

Code:

Thread *tfluid = Lookup_Thread(domain,FLUID_ID);

thread_loop_c(t,domain)
{
    if (t==tfluid)
        Message("This cell belongs to the fluid cell zone!");
}

where FLUID_ID is the integer value of the cell zone (found under cell zones in Fluent).

nima_nz January 8, 2016 15:43

Quote:

Originally Posted by `e` (Post 579820)
You can distinguish between cell zones using their threads. For example:

Code:

Thread *tfluid = Lookup_Thread(domain,FLUID_ID);

thread_loop_c(t,domain)
{
    if (t==tfluid)
        Message("This cell belongs to the fluid cell zone!");
}

where FLUID_ID is the integer value of the cell zone (found under cell zones in Fluent).

You mean I found the fluid thread at first and then import these thread to the main UDF?

`e` January 8, 2016 17:26

Quote:

Originally Posted by nima_nz (Post 580150)
You mean I found the fluid thread at first and then import these thread to the main UDF?

No, you only need one UDF. First, grab the cell zone ID via the GUI from Define > Cell Zone Conditions and selecting the corresponding cell zone. Second, use this integer in your UDF in place of FLUID_ID.

For good coding practice, you should define the cell zone ID at the beginning of the file (which replaces FLUID_ID with the integer, for example 10, everywhere in the code):

Code:

#define FLUID_ID 10

nima_nz January 10, 2016 02:45

Quote:

Originally Posted by `e` (Post 580154)
No, you only need one UDF. First, grab the cell zone ID via the GUI from Define > Cell Zone Conditions and selecting the corresponding cell zone. Second, use this integer in your UDF in place of FLUID_ID.

For good coding practice, you should define the cell zone ID at the beginning of the file (which replaces FLUID_ID with the integer, for example 10, everywhere in the code):

Code:

#define FLUID_ID 10

Dear `e`
The summary of the structure of my UDF is as follows:
#include "udf.h"
DEFINE_ON_DEMAND(myudftest)
{
Domain *d;
Thread *t;
cell_t c;
real parameters; /*defining parameters*/
real VEL; /* Relative air velocity (m/s)*/

d=Get_Domain(1);
.
.
.
thread_loop_c(t,d) {
begin_c_loop(c,t)
{
.
.
VEL=sqrt(pow(C_U(c,t),2.0)+pow(C_V(c,t),2.0)+pow(C _W(c,t),2.0));
.
.
C_UDMI(c,t,0)=...;

}
end_c_loop(c,t)
}
}
------------------------------
As you see, I need the velocity magnitude, but when I have solid domain because of lack of velocity in the solid domain, my UDF doesn't work.
If it's possible for you, would you please tell me what you mean?
You mean this?
#include "udf.h"
DEFINE_ON_DEMAND(myudftest)
{
Domain *d;
Thread *t;

cell_t c;
real parameters; /*defining parameters*/
real VEL; /* Relative air velocity (m/s)*/

.
.
.
Thread *tfluid=lookup_Thread(d,FLUID_ID for example 10)
thread_loop_c(t,d)
{
if (t==tfluid)
begin_c_loop(c,t)
{
.
.
VEL=sqrt(pow(C_U(c,t),2.0)+pow(C_V(c,t),2.0)+pow(C _W(c,t),2.0));
.
.
C_UDMI(c,t,0)=...;

}
end_c_loop(c,t)
}
}
---------------------
Thank you very much.

`e` January 10, 2016 20:42

Yes, only operate the velocity evaluation on the fluid cell zone thread.

A few comments: initialise your VEL variable with zero such that the solid will default to zero (and avoid errors when accessing VEL for solid cells); declare tfluid with the other declarations; and include curly brackets for the code block within the if statement (for clarity and in case the compiler misinterprets what you want).

nima_nz January 11, 2016 06:34

Quote:

Originally Posted by `e` (Post 580350)
Yes, only operate the velocity evaluation on the fluid cell zone thread.

A few comments: initialise your VEL variable with zero such that the solid will default to zero (and avoid errors when accessing VEL for solid cells); declare tfluid with the other declarations; and include curly brackets for the code block within the if statement (for clarity and in case the compiler misinterprets what you want).

Dear `e`
Thank you for your help and time.
I used this structure:
Code:

#include "udf.h"
DEFINE_ON_DEMAND(myudftest)
{
        Domain *d;
        Thread *tf;
        cell_t c;
        real parameter;       
.
.
.
        int ID=5;
        d=Get_Domain(1);
        tf=Lookup_Thread(d,ID);
.
.
.
        thread_loop_c(tf,d)       
        {

                        begin_c_loop(c,tf)
                        {
.
                                VEL=sqrt(pow(C_U(c,tf),2.0)+pow(C_V(c,tf),2.0)+pow(C_W(c,tf),2.0));
.
.
.
                                C_UDMI(c,tf,0)=name;
                        }
                        end_c_loop(c,tf)
        }
}

It's truly interpreted but after I write case and data in new name (as fluent say), and open that case, when I Execute on demand, by
define>user-defined>execute on demand
It doesn't work!
Is there any way to solve this problem?

pakk January 11, 2016 08:15

Quote:

Originally Posted by nima_nz (Post 580407)
It's truly interpreted but after I write case and data in new name (as fluent say), and open that case, when I Execute on demand, by
define>user-defined>execute on demand
It doesn't work!
Is there any way to solve this problem?

What do you mean "It doesn't work!"? Be more precise!
Do you get warnings?
Do you get wrong results?
Do you get no results?

I am surprised if this code interpreted without warnings, because of the line
Code:

C_UDMI(c,tf,0)=name;
What is "name" doing there?

nima_nz January 11, 2016 08:28

Quote:

Originally Posted by pakk (Post 580421)
What do you mean "It doesn't work!"? Be more precise!
Do you get warnings?
Do you get wrong results?
Do you get no results?

I am surprised if this code interpreted without warnings, because of the line
Code:

C_UDMI(c,tf,0)=name;
What is "name" doing there?

Hi,
I mean after I execute the UDM on demand, fluent give an error
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: ()
----------------------------------------------------
'name' is an example here. It isn't in my UDF.
For example first I define a function like F then I wrote:
Code:

C_UDMI(c,tf,0)=F;

pakk January 11, 2016 08:42

If you want us to find the problem in your UDF, you should show us the code of your UDF. Don't show us a version where you changed things and left out things.

nima_nz January 11, 2016 09:30

Quote:

Originally Posted by pakk (Post 580430)
If you want us to find the problem in your UDF, you should show us the code of your UDF. Don't show us a version where you changed things and left out things.

Dear Pakk,
It's a simple UDF to calculating operative temperature in the domain.
Code:

#include "udf.h"
DEFINE_ON_DEMAND(Opertemp)
{
        Domain *d;
        Thread *t;
        cell_t c;
        real TA;                /* Air temperature (°C)*/
        real TR;                /* Mean radiant temperature (°C)*/
        real VEL;                /* Relative air velocity (m/s)*/
        real OT;                /*operative temperature*/
        d=Get_Domain(1);        /* Get the domain using ANSYS FLUENT utility */
        thread_loop_c(t,d)        /* Loop over all cell threads in the domain */
        {
                begin_c_loop(c,t)        /* Loop over all cells */
                {
                        TA=C_T(c,t)-273.15;
                        TR=26.563;                /*Mean radiant temperature*/
                     
VEL=sqrt(pow(C_U(c,t),2.0)+pow(C_V(c,t),2.0)+pow(C_W(c,t),2.0));
                        OT=(TR+(TA*sqrt(10*VEL)))/(1+sqrt(10*VEL));
                        C_UDMI(c,t,0)=OT;
                }
                end_c_loop(c,t)
        }
}

As you see, I need velocity components in all cells, but because lack of velocity components in the solid domain when I execute the udf on the domain fluent give an error. I know it's because of velocity, because when I do this:
Code:

#include "udf.h"
DEFINE_ON_DEMAND(Opertemp)
{
        Domain *d;
        Thread *t;
        cell_t c;
        real TA;                /* Air temperature (°C)*/
        real TR;                /* Mean radiant temperature (°C)*/
        real VEL;                /* Relative air velocity (m/s)*/
        real OT;                /*operative temperature*/
        d=Get_Domain(1);        /* Get the domain using ANSYS FLUENT utility */
        thread_loop_c(t,d)        /* Loop over all cell threads in the domain */
        {
                begin_c_loop(c,t)        /* Loop over all cells */
                {
                        TA=C_T(c,t)-273.15;
                        TR=26.563;                /*Mean radiant temperature*/
                       
VEL=0.15;
                        OT=(TR+(TA*sqrt(10*VEL)))/(1+sqrt(10*VEL));
                        C_UDMI(c,t,0)=OT;
                }
                end_c_loop(c,t)
        }
}

after executing on demand, there is no error.
-------------------------------------------------
Thanks.

`e` January 11, 2016 18:15

The looping macro thread_loop_c(t,d) will always loop through all cell threads in a given domain (d). The cell thread pointer (t) is an output used within the code block; I suspect Fluent is ignoring your evaluation of "tf=Lookup_Thread(d,ID);" within this code block.

Have a careful read of my example above as your code was mostly correct before (using the conditional statement to check if the current thread in the loop was the fluid thread).

nima_nz January 12, 2016 03:09

Quote:

Originally Posted by `e` (Post 580522)
The looping macro thread_loop_c(t,d) will always loop through all cell threads in a given domain (d). The cell thread pointer (t) is an output used within the code block; I suspect Fluent is ignoring your evaluation of "tf=Lookup_Thread(d,ID);" within this code block.

Have a careful read of my example above as your code was mostly correct before (using the conditional statement to check if the current thread in the loop was the fluid thread).

Dear `e`
Thank you very very much.
I wrote my code like this:
Code:

#include "udf.h"
DEFINE_ON_DEMAND(Opertemp)
{
        Domain *d;
        Thread *t;
        cell_t c;
        int ID=29;
        Thread *tf=Lookup_Thread(d,ID);
        real TA;                /* Air temperature (°C)*/
        real TR;                /* Mean radiant temperature (°C)*/
        real VEL;                /* Relative air velocity (m/s)*/
        real OT;                /*operative temperature*/
        d=Get_Domain(1);        /* Get the domain using ANSYS FLUENT utility */
        thread_loop_c(t,d)        /* Loop over all cell threads in the domain */
        {
                if(t==tf)
                {
                        begin_c_loop(c,t)        /* Loop over all cells */
                        {
                                TA=C_T(c,t)-273.15;
                                TR=26.563;                /*Mean radiant temperature*/
                                VEL=sqrt(pow(C_U(c,t),2.0)+pow(C_V(c,t),2.0)+pow(C_W(c,t),2.0));
                                OT=(TR+(TA*sqrt(10*VEL)))/(1+sqrt(10*VEL));
                                C_UDMI(c,t,0)=OT;
                        }
                        end_c_loop(c,t)
                }
                else
                {
                        begin_c_loop(c,t)        /* Loop over all cells */
                        {
                                OT=0;
                                C_UDMI(c,t,0)=OT;
                        }
                        end_c_loop(c,t)
                }
        }
}

Now, there isn't any error, but something is wrong. because the contoure of 'Memory 0' is zero!
I think it's because of wrong Fluid thread ID. I find the fluid threads from boundary condition. Would you please tell me how I can find the true ID?
Thanks.

`e` January 12, 2016 17:29

If the UDM-0 is zero everywhere then you may have the wrong cell zone ID of the fluid thread.

Quote:

Originally Posted by `e` (Post 580154)
First, grab the cell zone ID via the GUI from Define > Cell Zone Conditions and selecting the corresponding cell zone.

Specifically: left click the fluid cell zone under "Zone" and read the integer underneath "ID" on the lower right of the panel. The "Type" should also be set to "fluid".

nima_nz January 13, 2016 02:45

Quote:

Originally Posted by `e` (Post 580715)
If the UDM-0 is zero everywhere then you may have the wrong cell zone ID of the fluid thread.



Specifically: left click the fluid cell zone under "Zone" and read the integer underneath "ID" on the lower right of the panel. The "Type" should also be set to "fluid".

Thanks a lot.


All times are GMT -4. The time now is 11:34.