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

UDM just for fluid zone

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree9Likes
  • 1 Post By nima_nz
  • 3 Post By `e`
  • 1 Post By nima_nz
  • 1 Post By `e`
  • 1 Post By `e`
  • 2 Post By `e`

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 6, 2016, 12:05
Default UDM just for fluid zone
  #1
Member
 
Nima
Join Date: May 2014
Location: Ireland
Posts: 51
Rep Power: 11
nima_nz is on a distinguished road
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
vavnoon likes this.
nima_nz is offline   Reply With Quote

Old   January 6, 2016, 14:45
Default
  #2
Member
 
Nima
Join Date: May 2014
Location: Ireland
Posts: 51
Rep Power: 11
nima_nz is on a distinguished road
i have tried to use the following macro FLUID_THREAD_P(t) but it is giving an error message, saying structure reference not implemented.
nima_nz is offline   Reply With Quote

Old   January 6, 2016, 16:41
Default
  #3
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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).
yakovlev-i-a, nima_nz and chek321 like this.
`e` is offline   Reply With Quote

Old   January 8, 2016, 16:43
Default
  #4
Member
 
Nima
Join Date: May 2014
Location: Ireland
Posts: 51
Rep Power: 11
nima_nz is on a distinguished road
Quote:
Originally Posted by `e` View Post
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?
zhixin likes this.
nima_nz is offline   Reply With Quote

Old   January 8, 2016, 18:26
Default
  #5
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Quote:
Originally Posted by nima_nz View Post
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 likes this.
`e` is offline   Reply With Quote

Old   January 10, 2016, 03:45
Default
  #6
Member
 
Nima
Join Date: May 2014
Location: Ireland
Posts: 51
Rep Power: 11
nima_nz is on a distinguished road
Quote:
Originally Posted by `e` View Post
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.
nima_nz is offline   Reply With Quote

Old   January 10, 2016, 21:42
Default
  #7
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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 likes this.
`e` is offline   Reply With Quote

Old   January 11, 2016, 07:34
Default
  #8
Member
 
Nima
Join Date: May 2014
Location: Ireland
Posts: 51
Rep Power: 11
nima_nz is on a distinguished road
Quote:
Originally Posted by `e` View Post
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?
nima_nz is offline   Reply With Quote

Old   January 11, 2016, 09:15
Default
  #9
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Quote:
Originally Posted by nima_nz View Post
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?
pakk is offline   Reply With Quote

Old   January 11, 2016, 09:28
Default
  #10
Member
 
Nima
Join Date: May 2014
Location: Ireland
Posts: 51
Rep Power: 11
nima_nz is on a distinguished road
Quote:
Originally Posted by pakk View Post
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;
nima_nz is offline   Reply With Quote

Old   January 11, 2016, 09:42
Default
  #11
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
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.
pakk is offline   Reply With Quote

Old   January 11, 2016, 10:30
Default
  #12
Member
 
Nima
Join Date: May 2014
Location: Ireland
Posts: 51
Rep Power: 11
nima_nz is on a distinguished road
Quote:
Originally Posted by pakk View Post
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.
nima_nz is offline   Reply With Quote

Old   January 11, 2016, 19:15
Default
  #13
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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 and zhixin like this.
`e` is offline   Reply With Quote

Old   January 12, 2016, 04:09
Default
  #14
Member
 
Nima
Join Date: May 2014
Location: Ireland
Posts: 51
Rep Power: 11
nima_nz is on a distinguished road
Quote:
Originally Posted by `e` View Post
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.
nima_nz is offline   Reply With Quote

Old   January 12, 2016, 18:29
Default
  #15
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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` View Post
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".
`e` is offline   Reply With Quote

Old   January 13, 2016, 03:45
Default
  #16
Member
 
Nima
Join Date: May 2014
Location: Ireland
Posts: 51
Rep Power: 11
nima_nz is on a distinguished road
Quote:
Originally Posted by `e` View Post
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.
nima_nz is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
[Commercial meshers] Mesh conversion problem (fluent3DMeshToFoam) Aadhavan OpenFOAM Meshing & Mesh Conversion 2 March 8, 2018 02:47
Possible Bug in pimpleFoam (or createPatch) (or fluent3DMeshToFoam) cfdonline2mohsen OpenFOAM 3 October 21, 2013 10:28
[Commercial meshers] fluentMeshToFoam multidomain mesh conversion problem Attesz OpenFOAM Meshing & Mesh Conversion 12 May 2, 2013 11:52
Problem in running ICEM grid in Openfoam Tarak OpenFOAM 6 September 9, 2011 18:51
Problem in IMPORT of ICEM input file in FLUENT csvirume FLUENT 2 September 9, 2009 02:08


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