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

Resolved: Changing boundary condition with UDF according to pressure outlet boundary

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 4 Post By alpemre

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 30, 2010, 08:43
Thumbs up Resolved: Changing boundary condition with UDF according to pressure outlet boundary
  #1
New Member
 
alpemre
Join Date: May 2010
Posts: 3
Rep Power: 16
alpemre is on a distinguished road
Hello everybody, my problem was:
I was trying to set a temperature to a velocity inlet in my problem according to the average temperature of the air leaving the domain from a pressure outlet. I searched through the forum to find a solution to this but I could not find a clear answer. Now I managed to write a parallel UDF (for 8 cpus) as a remedy to this problem. Hope this helps if you have the same problem:

Code:
#include "udf.h"

/* Average temperature is calculated and share with other CPUs */

DEFINE_ADJUST(average_exit_temp, domain)
{
#if !RP_HOST    /*  either serial or compute node process is involved */

	face_t f;
	real sum_temp=0.0;  
	int nfaces = 0, i; 
	int ID  = 21;	//on_hava_cikisi
	int ID0 = 31;	//uflec_orta_sag
	int ID1 = 30;	//uflec_orta_sol
	int ID2 = 28;	//uflec_sag
	int ID3 = 29;	//uflec_sag_cam
	int ID4 = 26;	//uflec_sol
	int ID5 = 27;	//uflec_sol_cam

	/* Determination of zone IDs */
	Thread *thread  = Lookup_Thread(domain, ID );
	Thread *thread0 = Lookup_Thread(domain, ID0);
	Thread *thread1 = Lookup_Thread(domain, ID1);
	Thread *thread2 = Lookup_Thread(domain, ID2);
	Thread *thread3 = Lookup_Thread(domain, ID3);
	Thread *thread4 = Lookup_Thread(domain, ID4);
	Thread *thread5 = Lookup_Thread(domain, ID5);

	/* Calculation of average exit temperature and sending to other nodes. The thread on which the average temperature is calculated is on node zero*/
	if(I_AM_NODE_ZERO_P)
	{
		begin_f_loop(f, thread)
		{
			nfaces = nfaces + 1;
			sum_temp = sum_temp + F_T(f,thread);
		}
		end_f_loop(f,thread)
		sum_temp = sum_temp/nfaces;
		Message("Node %d :  Average exit temperature = %f\n", myid, sum_temp);
		compute_node_loop_not_zero(i)
		{
			PRF_CSEND_REAL(i, &sum_temp, 1, myid);
		}
	}

	/* Reception of average temperature from node zero */
	if(! I_AM_NODE_ZERO_P)
	{
		PRF_CRECV_REAL(0, &sum_temp, 1, 0);
		Message("Node %d : Average exit temperature = %f\n", myid, sum_temp);
	}

	/* User defined memory of thread0 are filled with sum_temp */
	begin_f_loop(f, thread0)
	{
		F_UDMI(f,thread0,0) = sum_temp;
	}
	end_f_loop(f,thread0)

	/* User defined memory of thread1 are filled with sum_temp */
	begin_f_loop(f, thread1)
	{
		F_UDMI(f,thread1,1) = sum_temp;
	}
	end_f_loop(f,thread1)

	/* User defined memory of thread2 are filled with sum_temp */
	begin_f_loop(f, thread2)
	{
		F_UDMI(f,thread2,2) = sum_temp;
	}
	end_f_loop(f,thread2)

	/* User defined memory of thread3 are filled with sum_temp */
	begin_f_loop(f, thread3)
	{
		F_UDMI(f,thread3,3) = sum_temp;
	}
	end_f_loop(f,thread3)

	/* User defined memory of thread4 are filled with sum_temp */
	begin_f_loop(f, thread4)
	{
		F_UDMI(f,thread4,4) = sum_temp;
	}
	end_f_loop(f,thread4)

	/* User defined memory of thread5 are filled with sum_temp */
	begin_f_loop(f, thread5)
	{
		F_UDMI(f,thread5,5) = sum_temp;
	}
	end_f_loop(f,thread5)

#endif 
}

/* Boundary conditions are filled from user defined memory locations  */ 

DEFINE_PROFILE(temp_uflec_orta_sag,t,i)
{
	#if !RP_HOST
	face_t f;

	begin_f_loop(f,t)
	{
		F_PROFILE(f,t,i) = F_UDMI(f,t,0);
	}
	end_f_loop(f,t)
	#endif 
}

DEFINE_PROFILE(temp_uflec_orta_sol,t,i)
{
	#if !RP_HOST
	face_t f;

	begin_f_loop(f,t)
	{
		F_PROFILE(f,t,i) = F_UDMI(f,t,1);
	}
	end_f_loop(f,t)
	#endif 
}

DEFINE_PROFILE(temp_uflec_sag,t,i)
{
	#if !RP_HOST
	face_t f;

	begin_f_loop(f,t)
	{
		F_PROFILE(f,t,i) = F_UDMI(f,t,2);
	}
	end_f_loop(f,t)
	#endif 
}

DEFINE_PROFILE(temp_uflec_sag_cam,t,i)
{
	#if !RP_HOST
	face_t f;

	begin_f_loop(f,t)
	{
		F_PROFILE(f,t,i) = F_UDMI(f,t,3);
	}
	end_f_loop(f,t)
	#endif 
}

DEFINE_PROFILE(temp_uflec_sol,t,i)
{
	#if !RP_HOST
	face_t f;

	begin_f_loop(f,t)
	{
		F_PROFILE(f,t,i) = F_UDMI(f,t,4);
	}
	end_f_loop(f,t)
	#endif 
}

DEFINE_PROFILE(temp_uflec_sol_cam,t,i)
{
	#if !RP_HOST
	face_t f;

	begin_f_loop(f,t)
	{
		F_PROFILE(f,t,i) = F_UDMI(f,t,5);
	}
	end_f_loop(f,t)
	#endif 
}
alpemre
ghost82, virgy, wc34071209 and 1 others like this.
alpemre is offline   Reply With Quote

Old   January 3, 2011, 04:58
Default help
  #2
Member
 
EH
Join Date: Dec 2010
Posts: 61
Rep Power: 15
ehooi is on a distinguished road
Hi there,
Thank you very much for this. Can I know some of the function of the lines you have written?

1) Message("Node %d : Average exit temperature = %f\n", myid, sum_temp);

and

2)compute_node_loop_not_zero(i)

I am very new in UDF in ANSYS Fluent and will appreciate all the help I can get.

Thank you.


EH
ehooi is offline   Reply With Quote

Old   December 17, 2012, 16:46
Default How can I do the same job as you did but not for parallel nodes?
  #3
CMA
New Member
 
Join Date: Oct 2012
Posts: 8
Rep Power: 14
CMA is on a distinguished road
Hi,

I am trying to do the same with my code, but since it's not parallel, I am omitting every line in your code that relates to parallel CPUs. Here is my code:

#include "udf.h"

DEFINE_ADJUST(average_exit_temp, domain)
{

face_t f;
real tempa=0.0;
real totalarea=0.0;
real avetempa=0.0;
real A[ND_ND];

int ID1 = 4; /* Zone ID for Outflow zone from Boundary Conditions panel */
Thread *outlet_thread = Lookup_Thread(domain, ID1);

int ID2 = 7; /* Zone ID for Inlet zone from Boundary Conditions panel */
Thread *inlet_thread = Lookup_Thread(domain, ID2);

/* Loop over faces in a face thread to get the information stored on faces.*/
begin_f_loop(f,outlet_thread)
{
/* F_T gets face temperature. += causes all face areas/temperatures to be added together. */
totalarea += F_AREA(A,f,outlet_thread);
tempa += F_AREA(A,f,outlet_thread)*F_T(f,outlet_thread);
}
end_f_loop(f,outlet_thread)

avetempa = tempa/totalarea + 30*200/(0.561*4182);
printf("average temperature= %e\n",avetempa);

begin_f_loop(f, inlet_thread)
{
F_UDMI(f,inlet_thread,1) = avetempa;
}

}

DEFINE_PROFILE(Inlettemp,t,i)
{

real flow_time;
flow_time = RP_Get_Real("flow-time");
face_t face;

if(flow_time<=5.0)
{
printf("t= %e\n",flow_time);
begin_f_loop(face, t)
{
F_PROFILE(face, t, i)=283.0;
}
end_f_loop(face, t)
}

else
{

begin_f_loop(face, t)
{
F_PROFILE(face, t, i) = F_UDMI(f,t,1);
}
end_f_loop(face, t)
printf("t= %e\n",flow_time);
}
}

and I get a parse error on the Define_Profile line. Note that my case file and my c file are in the same directory. Do you have any idea what might be wrong here?

Thank you in advance for your help.

CMA

Quote:
Originally Posted by alpemre View Post
Hello everybody, my problem was:
I was trying to set a temperature to a velocity inlet in my problem according to the average temperature of the air leaving the domain from a pressure outlet. I searched through the forum to find a solution to this but I could not find a clear answer. Now I managed to write a parallel UDF (for 8 cpus) as a remedy to this problem. Hope this helps if you have the same problem:

Code:
#include "udf.h"

/* Average temperature is calculated and share with other CPUs */

DEFINE_ADJUST(average_exit_temp, domain)
{
#if !RP_HOST    /*  either serial or compute node process is involved */

	face_t f;
	real sum_temp=0.0;  
	int nfaces = 0, i; 
	int ID  = 21;	//on_hava_cikisi
	int ID0 = 31;	//uflec_orta_sag
	int ID1 = 30;	//uflec_orta_sol
	int ID2 = 28;	//uflec_sag
	int ID3 = 29;	//uflec_sag_cam
	int ID4 = 26;	//uflec_sol
	int ID5 = 27;	//uflec_sol_cam

	/* Determination of zone IDs */
	Thread *thread  = Lookup_Thread(domain, ID );
	Thread *thread0 = Lookup_Thread(domain, ID0);
	Thread *thread1 = Lookup_Thread(domain, ID1);
	Thread *thread2 = Lookup_Thread(domain, ID2);
	Thread *thread3 = Lookup_Thread(domain, ID3);
	Thread *thread4 = Lookup_Thread(domain, ID4);
	Thread *thread5 = Lookup_Thread(domain, ID5);

	/* Calculation of average exit temperature and sending to other nodes. The thread on which the average temperature is calculated is on node zero*/
	if(I_AM_NODE_ZERO_P)
	{
		begin_f_loop(f, thread)
		{
			nfaces = nfaces + 1;
			sum_temp = sum_temp + F_T(f,thread);
		}
		end_f_loop(f,thread)
		sum_temp = sum_temp/nfaces;
		Message("Node %d :  Average exit temperature = %f\n", myid, sum_temp);
		compute_node_loop_not_zero(i)
		{
			PRF_CSEND_REAL(i, &sum_temp, 1, myid);
		}
	}

	/* Reception of average temperature from node zero */
	if(! I_AM_NODE_ZERO_P)
	{
		PRF_CRECV_REAL(0, &sum_temp, 1, 0);
		Message("Node %d : Average exit temperature = %f\n", myid, sum_temp);
	}

	/* User defined memory of thread0 are filled with sum_temp */
	begin_f_loop(f, thread0)
	{
		F_UDMI(f,thread0,0) = sum_temp;
	}
	end_f_loop(f,thread0)

	/* User defined memory of thread1 are filled with sum_temp */
	begin_f_loop(f, thread1)
	{
		F_UDMI(f,thread1,1) = sum_temp;
	}
	end_f_loop(f,thread1)

	/* User defined memory of thread2 are filled with sum_temp */
	begin_f_loop(f, thread2)
	{
		F_UDMI(f,thread2,2) = sum_temp;
	}
	end_f_loop(f,thread2)

	/* User defined memory of thread3 are filled with sum_temp */
	begin_f_loop(f, thread3)
	{
		F_UDMI(f,thread3,3) = sum_temp;
	}
	end_f_loop(f,thread3)

	/* User defined memory of thread4 are filled with sum_temp */
	begin_f_loop(f, thread4)
	{
		F_UDMI(f,thread4,4) = sum_temp;
	}
	end_f_loop(f,thread4)

	/* User defined memory of thread5 are filled with sum_temp */
	begin_f_loop(f, thread5)
	{
		F_UDMI(f,thread5,5) = sum_temp;
	}
	end_f_loop(f,thread5)

#endif 
}

/* Boundary conditions are filled from user defined memory locations  */ 

DEFINE_PROFILE(temp_uflec_orta_sag,t,i)
{
	#if !RP_HOST
	face_t f;

	begin_f_loop(f,t)
	{
		F_PROFILE(f,t,i) = F_UDMI(f,t,0);
	}
	end_f_loop(f,t)
	#endif 
}

DEFINE_PROFILE(temp_uflec_orta_sol,t,i)
{
	#if !RP_HOST
	face_t f;

	begin_f_loop(f,t)
	{
		F_PROFILE(f,t,i) = F_UDMI(f,t,1);
	}
	end_f_loop(f,t)
	#endif 
}

DEFINE_PROFILE(temp_uflec_sag,t,i)
{
	#if !RP_HOST
	face_t f;

	begin_f_loop(f,t)
	{
		F_PROFILE(f,t,i) = F_UDMI(f,t,2);
	}
	end_f_loop(f,t)
	#endif 
}

DEFINE_PROFILE(temp_uflec_sag_cam,t,i)
{
	#if !RP_HOST
	face_t f;

	begin_f_loop(f,t)
	{
		F_PROFILE(f,t,i) = F_UDMI(f,t,3);
	}
	end_f_loop(f,t)
	#endif 
}

DEFINE_PROFILE(temp_uflec_sol,t,i)
{
	#if !RP_HOST
	face_t f;

	begin_f_loop(f,t)
	{
		F_PROFILE(f,t,i) = F_UDMI(f,t,4);
	}
	end_f_loop(f,t)
	#endif 
}

DEFINE_PROFILE(temp_uflec_sol_cam,t,i)
{
	#if !RP_HOST
	face_t f;

	begin_f_loop(f,t)
	{
		F_PROFILE(f,t,i) = F_UDMI(f,t,5);
	}
	end_f_loop(f,t)
	#endif 
}
alpemre
CMA is offline   Reply With Quote

Old   January 11, 2013, 09:13
Default
  #4
New Member
 
Join Date: Jan 2011
Posts: 3
Rep Power: 15
taff224 is on a distinguished road
Hi CMA,

Not sure if you have solved this ourself but as I am 'borrowing' your code I thought I better reply with the fix.

I think the error you have is that you don't have an

end_f_loop(f,inlet_thread)

at the end of the DEFINE_ADJUST()

The parse error kicks in once you leave the function so it looks like it is relatign to the next function, but it isn't as I am only using our first function and also got the parse error.

Taff
taff224 is offline   Reply With Quote

Old   January 11, 2013, 11:44
Default
  #5
CMA
New Member
 
Join Date: Oct 2012
Posts: 8
Rep Power: 14
CMA is on a distinguished road
Hi Taff,

There are a couple of errors in the above code including the one you mentioned. For example where I calculate the area of a face, my code gets the vector area which creates another error. However, if you are only using the general structure of the code, you will be fine. I will be happy to hear your suggestions, if there's any.

Quote:
Originally Posted by taff224 View Post
Hi CMA,

Not sure if you have solved this ourself but as I am 'borrowing' your code I thought I better reply with the fix.

I think the error you have is that you don't have an

end_f_loop(f,inlet_thread)

at the end of the DEFINE_ADJUST()

The parse error kicks in once you leave the function so it looks like it is relatign to the next function, but it isn't as I am only using our first function and also got the parse error.

Taff
CMA is offline   Reply With Quote

Old   January 11, 2013, 11:53
Default
  #6
New Member
 
Join Date: Jan 2011
Posts: 3
Rep Power: 15
taff224 is on a distinguished road
I'm struggling a bit to be honest, first attempt at UDFs and not quite sure I have it worked out.

For some reason my system isn't processing the begin_f_loop loop, I think because I am running multi-processor i have included the if(I_AM_ NODE_ZERO_P) and for some reason this is stopping the loop occuring, maybe the thread isn't in the node_zero processors area?

I'm sure I have something stupid going on.

If you have a working version would wouldn't mind sharing i'd like to have a look at it.

Thanks

Taff

Quote:
Originally Posted by CMA View Post
Hi Taff,

There are a couple of errors in the above code including the one you mentioned. For example where I calculate the area of a face, my code gets the vector area which creates another error. However, if you are only using the general structure of the code, you will be fine. I will be happy to hear your suggestions, if there's any.
taff224 is offline   Reply With Quote

Old   April 12, 2013, 00:16
Default
  #7
New Member
 
massoud
Join Date: Nov 2011
Posts: 20
Rep Power: 15
massoudepsilon is on a distinguished road
Thank you so much. It was really helpful
massoudepsilon is offline   Reply With Quote

Old   April 18, 2013, 03:39
Default
  #8
New Member
 
massoud
Join Date: Nov 2011
Posts: 20
Rep Power: 15
massoudepsilon is on a distinguished road
Hi. Sorry just one question. How can I find that my outlet thread is on which node? because in this code you said that "The thread on which the average temperature is calculated is on node zero"

thank you so much.
massoudepsilon is offline   Reply With Quote

Old   April 23, 2013, 12:43
Default answer to ehooi
  #9
New Member
 
alpemre
Join Date: May 2010
Posts: 3
Rep Power: 16
alpemre is on a distinguished road
Quote:
Originally Posted by ehooi View Post
1) Message("Node %d : Average exit temperature = %f\n", myid, sum_temp);
EH
This function is used by node 0 to write the average temperature which is calculated before and stored in sum_temp variable.

Quote:
Originally Posted by ehooi View Post
2)compute_node_loop_not_zero(i)
EH
This is to send a real variable from node 0 to all other nodes.
alpemre is offline   Reply With Quote

Old   April 24, 2013, 06:35
Default answer to massoud
  #10
New Member
 
alpemre
Join Date: May 2010
Posts: 3
Rep Power: 16
alpemre is on a distinguished road
Quote:
Originally Posted by massoudepsilon View Post
Hi. Sorry just one question. How can I find that my outlet thread is on which node? because in this code you said that "The thread on which the average temperature is calculated is on node zero"
I used this UDF years ago and I cannot remember now how I determined it Maybe it was so by chance and I found it out by trial and error.

Maybe you can try printing messages from different processors to determine it. Let me know if you learn how to do it.
alpemre is offline   Reply With Quote

Old   April 25, 2013, 01:04
Default
  #11
New Member
 
massoud
Join Date: Nov 2011
Posts: 20
Rep Power: 15
massoudepsilon is on a distinguished road
thank you so much dear alpemre, I found it by printing message.

Last edited by massoudepsilon; April 25, 2013 at 05:11.
massoudepsilon is offline   Reply With Quote

Old   September 9, 2013, 06:01
Default pressure inlet boundary vs to value of mass flow rate
  #12
New Member
 
mohammad azizi
Join Date: Sep 2013
Location: Iran, Tehran, TMU
Posts: 2
Rep Power: 0
mohammadamin67 is on a distinguished road
Hi all
I want to write a udf defining the value of the pressure in a pressure inlet boundary vs to value of mass flow rate passing that bouandary. can anyone help me or write this udf for me?
thanks.
M.Azizi
mohammadamin67 is offline   Reply With Quote

Old   February 24, 2014, 11:18
Default additionnal question...
  #13
New Member
 
Join Date: May 2009
Posts: 12
Rep Power: 17
frodooon is on a distinguished road
Hi all,

This post is quite old, but maybe someone will be able to answer this little question.

In the code above, alpemre use user defined memory for each thread, and then assign sum_temp to each one, to finally re-read it in separate DEFINE_PROFILE loops.. This seems quite long, and I'm wondering (since my C skills are quite low..) if we couldn't just declare some global variable "sum_temp", assign to it the computed average temp, and then just use something like F_PROFILE(f,t,i) = sum_temp; . So no more UDM needed. Would that work ?

Thank you,
frodooon is offline   Reply With Quote

Reply

Tags
change boundary condition, udf


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
Neumann Pressure Boundary Condition with UDF Balder Fluent UDF and Scheme Programming 8 July 6, 2012 12:21
pressure outlet boundary condition Sastry FLUENT 4 February 19, 2011 02:33
ATTENTION! Reliability problems in CFX 5.7 Joseph CFX 14 April 20, 2010 16:45
UDF for traction-free boundary condition at outlet psb Fluent UDF and Scheme Programming 0 November 10, 2009 03:40
Convective Heat Transfer - Heat Exchanger Mark CFX 6 November 15, 2004 16:55


All times are GMT -4. The time now is 23:47.