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

ANSYS UDF target temperature be a function of the physical flowrate

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By AlexanderZ

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 2, 2021, 11:40
Default ANSYS UDF target temperature be a function of the physical flowrate
  #1
Member
 
Ash Kotwal
Join Date: Jul 2016
Location: North Dakota, USA
Posts: 92
Blog Entries: 1
Rep Power: 9
Ash Kot is on a distinguished road


I'm trying to write UDF, which will govern the velocity or mass flowrate at inlet, to keep the tempreture defined at outlet constant at 120 degree Celsius.
can anyone find any mistakes in written UDF that I posted below



Code:
#include "udf.h" 

DEFINE_PROFILE(flowrate_Temp,c,t) 
{
	face_t f ;
	F_PROFILE(f,t,nv) = 1.0;
	real flow_tmp = C_T(c,t);
	if (flow_tmp > 120.)
		{
			printf("Tempreture   = %f celcius \n",flow_tmp);
			printf("Targeted mass-flow rate set at 3.0 kg/s \n");
			begin_f_loop(f,t)
			{
				F_PROFILE(f,t,nv) = 3.0;
			}
			end_f_loop(f,t)
		}
		else if (flow_tmp < 120.)
		{
			printf("Time   = %f celcius \n",flow_tmp);
			printf("Targeted mass-flow rate set at 2.0 kg/s \n");
			begin_f_loop(f,t)
			{
				F_PROFILE(f,t,nv) = 2.0;
			}
			end_f_loop(f,t)
		}
		else if (flow_tmp == 120.)
		{
			printf("Time   = %f celcius \n",flow_tmp);
			printf("Targeted mass-flow rate set at 1.5 kg/s \n");
			begin_f_loop(f,t)
			{
				F_PROFILE(f,t,nv) = 1.5;
			}
			end_f_loop(f,t)
		}

}
Ash Kot is offline   Reply With Quote

Old   February 2, 2021, 13:36
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Have you tried it? Does it seem to do what you want?
pakk is offline   Reply With Quote

Old   February 2, 2021, 18:04
Default
  #3
Member
 
Ash Kotwal
Join Date: Jul 2016
Location: North Dakota, USA
Posts: 92
Blog Entries: 1
Rep Power: 9
Ash Kot is on a distinguished road
Quote:
Originally Posted by pakk View Post
Have you tried it? Does it seem to do what you want?
Nope, didn't work!
I received error on this line

Code:
F_PROFILE(f,t,nv) = 1.0;
I actually, want to setup a value at initially, let say 1.0-kg/s.
Then I want UDF to find out corresponding tempreture at outlet based upon the flowrate.
then it goes through conditional statement, that is, if the tempreture is less than specified/desired value. then the UDF will change the flowrate.
and again the iterations will run.
like that, it shall reach to desired value, of outlet tempreture, after than keep running the iterations until it reaches to solution convergence.
Ash Kot is offline   Reply With Quote

Old   February 2, 2021, 21:04
Default
  #4
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
your header is wonrg
you've mixed up cells with faces

compile the code and read log, fix errors
read ansys fluent customization manual for examples

if you want to apply profile to boundary use faces (F_PROFILE(f,t,i), F_T(f,t)), to apply to zones use cells (F_PROFILE(c,t,i), C_T(c,t))
Ash Kot likes this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   February 4, 2021, 13:12
Default
  #5
Member
 
Ash Kotwal
Join Date: Jul 2016
Location: North Dakota, USA
Posts: 92
Blog Entries: 1
Rep Power: 9
Ash Kot is on a distinguished road
Hello,

First of all, thank you 'AlexanderZ', and 'pakk' for replying quickly and effectively to post. I guess, and I don't want to do a comparison here, but based upon the responses, the ANSYS forum is faster and more active than the OpenFOAM forum.

Alrighty going back to the post, so this is the newly written UDF code:

Code:
#include "udf.h" 

DEFINE_PROFILE(flowrate_TempBased,t,i) 
{
	face_t f ;
	F_PROFILE(f,t,i) = 1.0;
	real flow_tmp = F_T(f,t);
	if (flow_tmp > 774.)
		{
			printf("Tempreture   = %f celcius \n",flow_tmp);
			printf("Targeted mass-flow rate set at 3.0 kg/s \n");
			begin_f_loop(f,t)
			{
				F_PROFILE(f,t,i) = 3.0;
			}
			end_f_loop(f,t)
		}
		else if (flow_tmp < 772.)
		{
			printf("Time   = %f celcius \n",flow_tmp);
			printf("Targeted mass-flow rate set at 2.0 kg/s \n");
			begin_f_loop(f,t)
			{
				F_PROFILE(f,t,i) = 2.0;
			}
			end_f_loop(f,t)
		}
		else if (flow_tmp == 773.)
		{
			printf("Time   = %f celcius \n",flow_tmp);
			printf("Targeted mass-flow rate set at 1.5 kg/s \n");
			begin_f_loop(f,t)
			{
				F_PROFILE(f,t,i) = 1.5;
			}
			end_f_loop(f,t)
		}

}
But once again, what I want to do is:
1. First, I define a certain flowrate during initialization or at the first line of the above-defined UDF.
2. That flowrate will be used for a certain number of iterations until it reaches the particular value of temperature, lets say 120°C.
3. now, the UDF will follow the if loop in which it will see if the temperature reached the desired temperature or not if the desired temperature is 124°C, then it shall increase the flowrate value to 'current_flowrate + 0.01'.
4. Now if the temperature reaches to, let's say 130°C, then it will follow the next if loop where it does 'current_flowrate - 0.01' execution.
5. Once the temperature reaches to the desired value, which is 124°C, it'll keep iterating with that constant value of the temperature until residuals reach to set convergence value.

And then, I want to do a set of 500 iterations in between these outlet face temperature checks.

Now all these things how to do that?
for example: does current running flowrate or velocity can be acquired the same way as the time is acquired, which is:
Code:
time=CURRENT_TIME;                                   OR

real t = RP_Get_Real("flow-time");
so similar to that, are these valid statements?:

Code:
flowrate=CURRENT_FLOWRATE;      OR

real fl = RP_Get_Real("flow-rate");
are these valid statements?:

Code:
Temp=CURRENT_TEMP;      OR

real T = RP_Get_Real("tempreture");
Ash Kot is offline   Reply With Quote

Old   February 4, 2021, 17:17
Default
  #6
Member
 
Ash Kotwal
Join Date: Jul 2016
Location: North Dakota, USA
Posts: 92
Blog Entries: 1
Rep Power: 9
Ash Kot is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
your header is wonrg
you've mixed up cells with faces

compile the code and read log, fix errors
read ansys fluent customization manual for examples

if you want to apply profile to boundary use faces (F_PROFILE(f,t,i), F_T(f,t)), to apply to zones use cells (F_PROFILE(c,t,i), C_T(c,t))
Hello,

So this is what I got for the above defined requirement for UDF, please correct me if I am wrong

Code:
DEFINE_PROFILE(velocity_TempBased,th,position)
{
	Domain *d;
	face_t f;
	real t_avg = 0.;
	Thread *t;
	real tmp_e,vol,vol_tot,area;

	real A[ND_ND];

	d = Get_Domain(1);

	thread_loop_f(t,d)
	{
		if (THREAD_ID(t) == 11)
		{
			begin_f_loop(f,t)
			{
				vol = F_AREA(A,f,t); /* get cell volume */
				tmp_e = F_T(f,t);
				area = NV_MAG(A);

				vol_tot += area;
				t_avg += (tmp_e*area);
			}
			end_f_loop(f,t)
			t_avg /= vol_tot;
		}
	}
	begin_f_loop(f,th)
	{
		if (t_avg = 301.)
			F_PROFILE(t,th,position) = 0.1;
		if (t_avg > 301.)
			F_PROFILE(f,th,position) = 0.;
	}
	end_f_loop(f,th)
}
Ash Kot is offline   Reply With Quote

Old   February 5, 2021, 12:15
Default
  #7
Member
 
Ash Kotwal
Join Date: Jul 2016
Location: North Dakota, USA
Posts: 92
Blog Entries: 1
Rep Power: 9
Ash Kot is on a distinguished road
Hello All,

This is another UDF I have generated, haven't got chance to run it yet.
Posting here on website, because if anyone wants to try it. Feel free!

Although, couple of things I still not been able to figure it out:
1. Instead of providing fixed value for flowrate/velocity at inlet in each if loop as the tempreture at outlet face changes, I not able to figure it out how to provide the value for flowrate/velocity at inlet as 'current_flowrate + 0.01' or 'current_flowrate - 0.01', where 'current_flowrate' is taken from FLUENT system.
2. How to let fluent run the solver with the specific settings for few iterations, let say 500 iterations, and then allow it read the tempreture at outlet face, and as per that change the inlet flowrate or velocity value.

Code:
#include "udf.h"

DEFINE_PROFILE(velocity_TempBased,th,position)
{
	Domain *d;
	face_t f;
	real t_avg = 0.;
	Thread *t;
	real tmp_e,vol,vol_tot,area;

	real A[ND_ND];

	d = Get_Domain(1);

	thread_loop_f(t,d)
	{
		if (THREAD_ID(t) == 11)
		{
			begin_f_loop(f,t)
			{
				vol = F_AREA(A,f,t); /* get cell volume */
				tmp_e = F_T(f,t);
				area = NV_MAG(A);

				vol_tot += area;
				t_avg += (tmp_e*area);
			}
			end_f_loop(f,t)
			t_avg /= vol_tot;
		}
	}
	begin_f_loop(f,th)
	{
	if (t_avg > 774.)
		{
			printf("Tempreture   = %f Kelvin \n",t_avg);
			printf("Targeted mass-flow rate set at 3.0 kg/s \n");
			begin_f_loop(f,t)
			{
				F_PROFILE(f,t,i) = 3.0;
			}
			end_f_loop(f,t)
		}
		else if (t_avg < 772.)
		{
			printf("Time   = %f Kelvin \n",t_avg);
			printf("Targeted mass-flow rate set at 2.0 kg/s \n");
			begin_f_loop(f,t)
			{
				F_PROFILE(f,t,i) = 2.0;
			}
			end_f_loop(f,t)
		}
		else if (t_avg == 773.)
		{
			printf("Time   = %f Kelvin \n",t_avg);
			printf("Targeted mass-flow rate set at 1.5 kg/s \n");
			begin_f_loop(f,t)
			{
				F_PROFILE(f,t,i) = 1.5;
			}
			end_f_loop(f,t)
		}
	}
	end_f_loop(f,th)
}

Last edited by Ash Kot; February 5, 2021 at 12:22. Reason: Forgot to add the things that I haven't been able to accomplish yet
Ash Kot is offline   Reply With Quote

Old   March 8, 2021, 23:49
Default
  #8
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
you may use journal file to control number of iterations
according to your code, compile it first and read log
as far as I know, there is no "current_flowrate" build_in macro so you should make it by your own.
there are few threads which discuss how to get flow rate
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   January 22, 2024, 09:08
Default
  #9
New Member
 
Join Date: Nov 2023
Posts: 2
Rep Power: 0
Unda Calore is on a distinguished road
Hello, I need exactly such a UDF code. Were you able to solve the problem? If you solved it, can you share it? Thank you...
Unda Calore 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
UDF to get the average temperature of a face and use it to define a property gdb Fluent UDF and Scheme Programming 19 November 3, 2022 03:11
How To write a Correct UDF (FLUENT) for Specific heat as Function of Temperature for atulsbhat FLUENT 4 December 10, 2019 10:57
Calculation of the Governing Equations Mihail CFX 7 September 7, 2014 06:27
ParaView for OF-1.6-ext Chrisi1984 OpenFOAM Installation 0 December 31, 2010 06:42
Droplet Evaporation Christian Main CFD Forum 2 February 27, 2007 06:27


All times are GMT -4. The time now is 14:44.