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

Asking about UDF of Pressure Inlet Boundary Condition

Register Blogs Community New Posts Updated Threads Search

Like Tree6Likes
  • 1 Post By pakk
  • 1 Post By AlexanderZ
  • 1 Post By AlexanderZ
  • 1 Post By AlexanderZ
  • 1 Post By AlexanderZ
  • 1 Post By AlexanderZ

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 17, 2019, 02:39
Default Asking about UDF of Pressure Inlet Boundary Condition
  #1
New Member
 
Pham Van Chien
Join Date: Oct 2018
Location: Korea
Posts: 9
Rep Power: 7
Pham Van Chien is on a distinguished road
Dear CFD Experts,

I am trying to simulate the combustion process of an internal combustion engine. In my simulation, the fuel injection is an intermittent process, not a continuous process.

The following is the injection feature:
- The inlet pressure will be 180bar (18238500 Pa) if time <= 0.03333333 seconds.
- The inlet pressure will be 0bar if time > 0.03333333 seconds.

The following is the UDF that I tried to use:

#include "udf.h"
DEFINE_PROFILE(inlet_press,th,i)
{
real pressure_profile;
face_t f;
real t = CURRENT_TIME;
begin_f_loop(f,th)
{
if (CURRENT_TIME <= 0.03333333)
{
pressure_profile = 18238500;
}
else
{
pressure_profile = 0;
}
F_PROFILE(f,th,i) = pressure_profile;
}
end_f_loop(f,th);
}

However, when evaluating the results (velocity contour), I realized that the fuel injection feature is not the same as I wanted, it is still a continuous injection process with a constant pressure of 180bar from the beginning to the end of the simulation.

I have no experience in writing UDF, so I have not found the wrong points I have made. Hope you see my UDF and give me advice on how I should edit my UFD.

I posted this thread looking forward to receiving everyone's help. Your help is really helpful to me.

Thank in advance!

Pham Van Chien
Pham Van Chien is offline   Reply With Quote

Old   January 17, 2019, 06:12
Default
  #2
Senior Member
 
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,674
Rep Power: 65
LuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura about
CURRENT_TIME is a macro not a variable, and I forget its return structure when called to be evaluated. Instead of

Code:
if (CURRENT_TIME <= 0.03333333)
try
Code:
if (t <= 0.03333333)
LuckyTran is offline   Reply With Quote

Old   January 17, 2019, 07:06
Default
  #3
New Member
 
Pham Van Chien
Join Date: Oct 2018
Location: Korea
Posts: 9
Rep Power: 7
Pham Van Chien is on a distinguished road
Dear Mr. LuckyTran,

Thank you so much for your replying.
I will edit my UDF as your advice and calculate the solution again for checking the edited UDF.

Hope to continue to receive your advice in the future.

Best Regards
Pham Van Chien
Pham Van Chien is offline   Reply With Quote

Old   December 3, 2020, 04:04
Question Transient pressure inlet
  #4
Member
 
Sesh
Join Date: Dec 2018
Posts: 42
Rep Power: 7
virothi is on a distinguished road
Dear Pham,
did you try the edited code?

Did it work? I want to solve a similar problem.

Quote:
Originally Posted by Pham Van Chien View Post
Dear Mr. LuckyTran,

Thank you so much for your replying.
I will edit my UDF as your advice and calculate the solution again for checking the edited UDF.

Hope to continue to receive your advice in the future.

Best Regards
Pham Van Chien
virothi is offline   Reply With Quote

Old   December 4, 2020, 04:06
Question Transient pressure inlet
  #5
Member
 
Sesh
Join Date: Dec 2018
Posts: 42
Rep Power: 7
virothi is on a distinguished road
Dear Lucky Tran,

Could you please comment on the following UDF.

My simulation is similar to as stated in the above discussion. I have a pressure inlet but the pressure decreases gradually with time, and after 3 seconds there is no flow into the domain from the inlet.

I've used a UDF but I can see the pressure velocity profiles still after 3 seconds. I'm not familiar with coding. I need some suggestions and if I made a mistake please correct me.

/************************************************** ********************
unsteady.c
UDF for specifying a transient pressure profile boundary condition
************************************************** *********************/

#include "udf.h"
DEFINE_PROFILE(inlet_press,th,i)
{
real pressure_profile;
face_t f;
real t = CURRENT_TIME;
begin_f_loop(f,th)
{
if (t <= 0.5)
{
pressure_profile = 150000;
}
else if (0.5 <= t <= 1)
{
pressure_profile = 140000;
}
else if (1 <= t <= 1.5)
{
pressure_profile = 130000;
}
else if (1.5 <= t <= 2.3)
{
pressure_profile = 120000;
}
else if (2.3 <= t <= 3)
{
pressure_profile = 110000;
}
else
{
pressure_profile = 0;
}
F_PROFILE(f,th,i) = pressure_profile;
}
end_f_loop(f,th);
}

Quote:
Originally Posted by LuckyTran View Post
CURRENT_TIME is a macro not a variable, and I forget its return structure when called to be evaluated. Instead of

Code:
if (CURRENT_TIME <= 0.03333333)
try
Code:
if (t <= 0.03333333)
virothi is offline   Reply With Quote

Old   December 4, 2020, 14:14
Default
  #6
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Quote:
Originally Posted by virothi View Post
else if (0.5 <= t <= 1)
This does not do what you expect. Split it :
Code:
else if ( (0.5<=t)&&(t<=1))
Better yet: you know that t is not smaller than 0.5 at this point, so simplify to
Code:
else if (t<=1)
virothi likes this.
pakk is offline   Reply With Quote

Old   December 29, 2020, 08:23
Default Temperature should rise as a step
  #7
Member
 
Sesh
Join Date: Dec 2018
Posts: 42
Rep Power: 7
virothi is on a distinguished road
Dear Pak,
Thanks for the instantaneous reply.

In addition, I've one more concern.

In this heat transfer problem, after some time (let's say some xx minutes), the temperature of the solid reaches 380K (threshold value). After reaching this threshold value, the temperature of the solid should increase as a step up to 700K.

I've done this in COMSOL using 'events'. How to achieve this in Fluent?

Thank you


Quote:
Originally Posted by pakk View Post
This does not do what you expect. Split it :
Code:
else if ( (0.5<=t)&&(t<=1))
Better yet: you know that t is not smaller than 0.5 at this point, so simplify to
Code:
else if (t<=1)
virothi is offline   Reply With Quote

Old   December 30, 2020, 05:36
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
in fluent interface check zone ID of your solid.

With UDF find temperature of that solid zone using loop over cells in that thread (in other words in that zone)

If criteria is met, change temperature in solid zone
virothi likes this.
__________________
best regards


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

Old   January 3, 2021, 11:26
Default Writing UDF
  #9
Member
 
Sesh
Join Date: Dec 2018
Posts: 42
Rep Power: 7
virothi is on a distinguished road
Dear Alexander, thanks for sharing your knowledge.

But to be honest, I've no idea in writing UDF, I tried to figure it out by looking at the user manuals and some tutorials online but no one has done this or at least a similar one.
So, could you please write an example UDF for this issue. the zone id's are 78, 81, 98 (example).
This would be a great help.

and moreover, I have no idea where to interpret this UDF in this problem. For example, when we are using a UDF for inlet velocity, we can interpret this in the boundary condition. But in the above case, I don't know where to interpret the UDF.

Thank you.

Quote:
Originally Posted by AlexanderZ View Post
in fluent interface check zone ID of your solid.

With UDF find temperature of that solid zone using loop over cells in that thread (in other words in that zone)

If criteria is met, change temperature in solid zone
virothi is offline   Reply With Quote

Old   January 11, 2021, 06:27
Default Updating temperature values after reaching threshold values
  #10
Member
 
Sesh
Join Date: Dec 2018
Posts: 42
Rep Power: 7
virothi is on a distinguished road
Could someone sort this out for me.

I have a reply from one person, but I'm not sure how to interpret or implement it.

In this heat transfer problem, after some time (let's say some xx minutes), the temperature of the solid reaches 380K (threshold value). After reaching this threshold value, the temperature of the solid should increase as a step up to 700K.

I've done this in COMSOL using 'events'. How to achieve this in Fluent?

Thank you[/QUOTE]
virothi is offline   Reply With Quote

Old   January 13, 2021, 02:16
Default
  #11
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
the thing is, you are writing code by your own, learn how to do it.
if code doesnt work, you put it here with description of problems
users are trying to help you if possible, others can learn something from your case either

as an exception I'm giving you this code(only because the main part of it is in examples in manual, ansys fluent customization manual)

this is code for zone 78 only. for other zones you should do it by your own.
you may make 3 define_adjust macro for each zone, or modify this macro to call it for 3 zones

compile code

Code:
#include "udf.h"

DEFINE_ADJUST(check_temperature_zone78, d)
{
	real tavg = 0.;
	real temp,volume,vol_tot;
	Thread *t;
	int nid = 78;
	cell_t c;

	t = Lookup_Thread (d, nid);

	/* Loop over all cells in zone with id 78*/
	begin_c_loop(c,t)
	{
		volume = C_VOLUME(c,t); /* get cell volume */
		temp = C_T(c,t); /* get cell temperature */
		vol_tot += volume;
		tavg += temp*volume;
	}
	end_c_loop(c,t)
	#if RP_NODE
	vol_tot = PRF_GRSUM1(vol_tot);
	tavg = PRF_GRSUM1(tavg)
	#endif /* RP_NODE */
	tavg /= vol_tot;
	Message0("Agerage temperature of zone %d is Tavg = %f\n",nid,tavg);
	/* Check criteria, 380K*/
	if (tavg > 380)
	{
		begin_c_loop(c,t)
		{
			C_T(c,t) = 700;
		}
		end_c_loop(c,t)
	}
}
virothi likes this.
__________________
best regards


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

Old   January 20, 2021, 10:49
Default
  #12
Member
 
Sesh
Join Date: Dec 2018
Posts: 42
Rep Power: 7
virothi is on a distinguished road
Dear Alexanderz, thank you so much for the code.

But I encountered issues during compiling.

I have managed to resolve a syntax error, but due to my poor knowledge of coding, I'm left with one warning.

The code is:

/************************************************** ********************
unsteady.c
UDF for changing temperature
************************************************** *********************/

#include "udf.h"

DEFINE_ADJUST(check_temperature_zone38, d)
{
real tavg = 0;
real temp,volume,vol_tot;
Thread *t;
int nid = 38;
cell_t c;

t = Lookup_Thread (d, nid);

/* Loop over all cells in zone with id 38*/
begin_c_loop(c,t)
{
volume = C_VOLUME(c,t); /* get cell volume */
temp = C_T(c,t); /* get cell temperature */
vol_tot += volume;
tavg += temp*volume;
}
end_c_loop(c,t)
#if RP_NODE
vol_tot = PRF_GRSUM1(vol_tot);
tavg = PRF_GRSUM1(tavg);
#endif /* RP_NODE */
tavg /= vol_tot;
Message0("Agerage temperature of zone %d is Tavg = %f\n",nid,tavg);
/* Check criteria, 301K*/
if (tavg > 301)
{
begin_c_loop(c,t)
{
C_T(c,t) = 700;
}
end_c_loop(c,t)
}
}



And the warning during compiling:

"warning C4700: uninitialized local variable 'vol_tot' used"

May be because of this warning, the results are unchanged which are actually supposed to change after compiling this code.



And here is what it shows after clicking 'build'

Copied H:\Lithium\Mesh\Codes\Code editors/H:\Lithium\Mesh\Codes\Code editors\zone38.c to libudf\src
Creating user_nt.udf file for 3ddp_host ...
(system "copy "C:\PROGRA~1\ANSYSI~1\v192\fluent"\fluent19.2.0\sr c\udf\makefile_nt.udf "libudf\win64\3ddp_host\makefile" ")
1 file(s) copied.
(chdir "libudf")(chdir "win64\3ddp_host")# Generating ud_io1.h
zone38.c
H:\Lithium\Mesh\Codes\Code editors\libudf\src\zone38.c(23) : warning C4700: uninitialized local variable 'vol_tot' used
# Generating udf_names.c because of makefile zone38.obj
udf_names.c
# Linking libudf.dll because of makefile user_nt.udf udf_names.obj zone38.obj
Microsoft (R) Incremental Linker Version 14.28.29336.0
Copyright (C) Microsoft Corporation. All rights reserved.

Creating library libudf.lib and object libudf.exp
Creating user_nt.udf file for 3ddp_node ...
(system "copy "C:\PROGRA~1\ANSYSI~1\v192\fluent"\fluent19.2.0\sr c\udf\makefile_nt.udf "libudf\win64\3ddp_node\makefile" ")
1 file(s) copied.
(chdir "libudf")(chdir "win64\3ddp_node")# Generating ud_io1.h
zone38.c
H:\Lithium\Mesh\Codes\Code editors\libudf\src\zone38.c(23) : warning C4700: uninitialized local variable 'vol_tot' used
# Generating udf_names.c because of makefile zone38.obj
udf_names.c
# Linking libudf.dll because of makefile user_nt.udf udf_names.obj zone38.obj
Microsoft (R) Incremental Linker Version 14.28.29336.0
Copyright (C) Microsoft Corporation. All rights reserved.

Creating library libudf.lib and object libudf.exp

Done.



Quote:
Originally Posted by AlexanderZ View Post
the thing is, you are writing code by your own, learn how to do it.
if code doesnt work, you put it here with description of problems
users are trying to help you if possible, others can learn something from your case either

as an exception I'm giving you this code(only because the main part of it is in examples in manual, ansys fluent customization manual)

this is code for zone 78 only. for other zones you should do it by your own.
you may make 3 define_adjust macro for each zone, or modify this macro to call it for 3 zones

compile code

Code:
#include "udf.h"

DEFINE_ADJUST(check_temperature_zone78, d)
{
	real tavg = 0.;
	real temp,volume,vol_tot;
	Thread *t;
	int nid = 78;
	cell_t c;

	t = Lookup_Thread (d, nid);

	/* Loop over all cells in zone with id 78*/
	begin_c_loop(c,t)
	{
		volume = C_VOLUME(c,t); /* get cell volume */
		temp = C_T(c,t); /* get cell temperature */
		vol_tot += volume;
		tavg += temp*volume;
	}
	end_c_loop(c,t)
	#if RP_NODE
	vol_tot = PRF_GRSUM1(vol_tot);
	tavg = PRF_GRSUM1(tavg)
	#endif /* RP_NODE */
	tavg /= vol_tot;
	Message0("Agerage temperature of zone %d is Tavg = %f\n",nid,tavg);
	/* Check criteria, 380K*/
	if (tavg > 380)
	{
		begin_c_loop(c,t)
		{
			C_T(c,t) = 700;
		}
		end_c_loop(c,t)
	}
}

Last edited by virothi; January 20, 2021 at 12:34.
virothi is offline   Reply With Quote

Old   January 21, 2021, 01:09
Default
  #13
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
was
Code:
t = Lookup_Thread (d, nid);

/* Loop over all cells in zone with id 38*/
begin_c_loop(c,t)
to be
Code:
t = Lookup_Thread (d, nid);
vol_tot = 0;
/* Loop over all cells in zone with id 38*/
begin_c_loop(c,t)
virothi likes this.
__________________
best regards


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

Old   January 21, 2021, 05:06
Default
  #14
Member
 
Sesh
Join Date: Dec 2018
Posts: 42
Rep Power: 7
virothi is on a distinguished road
Dear Alexanderz,
I really appreciate your interest in solving the issues posted.

I've now successfully compiled the code without any errors.

But I can see that there is no change in the temperature profile after compiling the code and running the simulation.


I have attached 3 screenshots
1. After clicking build
2. After clicking Load
3. After running the simulation.

I gave it for zone 37 and asked to change the temperature to 700K after reaching an average temperature of 301K in that zone.

Here is the entire code which you have provided me after editing

Code:
#include "udf.h"

DEFINE_ADJUST(check_temperature_zone37, d)
{
	real tavg = 0;
	real temp,volume,vol_tot;
	Thread *t;
	int nid = 37;
	cell_t c;

	t = Lookup_Thread (d, nid);
	vol_tot = 0;
	/* Loop over all cells in zone with id 37*/
	begin_c_loop(c,t)
	{
		volume = C_VOLUME(c,t); /* get cell volume */
		temp = C_T(c,t); /* get cell temperature */
		vol_tot += volume;
		tavg += temp*volume;
	}
	end_c_loop(c,t)
	#if RP_NODE
	vol_tot = PRF_GRSUM1(vol_tot);
	tavg = PRF_GRSUM1(tavg);
	#endif /* RP_NODE */
	tavg /= vol_tot;
	Message0("Agerage temperature of zone %d is Tavg = %f\n",nid,tavg);
	/* Check criteria, 301K*/
	if (tavg > 301)
	{
		begin_c_loop(c,t)
		{
			C_T(c,t) = 700;
		}
		end_c_loop(c,t)
	}
}


Quote:
Originally Posted by AlexanderZ View Post
was
Code:
t = Lookup_Thread (d, nid);

/* Loop over all cells in zone with id 38*/
begin_c_loop(c,t)
to be
Code:
t = Lookup_Thread (d, nid);
vol_tot = 0;
/* Loop over all cells in zone with id 38*/
begin_c_loop(c,t)
Attached Images
File Type: jpg Result.jpg (98.6 KB, 5 views)
File Type: png Build.PNG (34.6 KB, 5 views)
File Type: png Load.PNG (34.2 KB, 4 views)
virothi is offline   Reply With Quote

Old   January 21, 2021, 05:25
Default
  #15
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
most likely you didn't hook adjust function

user-defined -> function hooks -> adjust -> select udf function

you should have message in console on each timestep:
Agerage temperature of zone 37 is Tavg = ....
virothi likes this.
__________________
best regards


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

Old   January 21, 2021, 05:33
Default
  #16
Member
 
Sesh
Join Date: Dec 2018
Posts: 42
Rep Power: 7
virothi is on a distinguished road
Thank you.

I did it and it worked. cheers to your patience and explanations.

Quote:
Originally Posted by AlexanderZ View Post
most likely you didn't hook adjust function

user-defined -> function hooks -> adjust -> select udf function

you should have message in console on each timestep:
Agerage temperature of zone 37 is Tavg = ....
virothi is offline   Reply With Quote

Old   January 25, 2021, 09:43
Default
  #17
Member
 
Sesh
Join Date: Dec 2018
Posts: 42
Rep Power: 7
virothi is on a distinguished road
Dear Alexanderz, could you please share your comments on the attached results.

After setting up a step increase in temperature up to 700K, I can see the temperature is not getting down which is unrealistic during heat transfer.

Is this because of the code which we compiled??

Best regards.

Quote:
Originally Posted by AlexanderZ View Post
most likely you didn't hook adjust function

user-defined -> function hooks -> adjust -> select udf function

you should have message in console on each timestep:
Agerage temperature of zone 37 is Tavg = ....
Attached Images
File Type: jpg 1.5mm mesh.jpg (123.1 KB, 8 views)
virothi is offline   Reply With Quote

Old   January 25, 2021, 21:34
Default
  #18
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
in code you have criteria
Code:
if (tavg > 301)
C_T(c,t) = 700;
temperature can be lower than 301 or 700
change condition statement, if you want something else
virothi likes this.
__________________
best regards


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

Old   February 17, 2021, 11:09
Question Write file: data didn't save completely
  #19
Member
 
Sesh
Join Date: Dec 2018
Posts: 42
Rep Power: 7
virothi is on a distinguished road
In the report definitions, I have created a 'report plot' and 'write file' to visualize the temperature w.r.t flow time. I can see the plots while the simulation is running but the data saved in 'write file' is only upto 2.4 seconds for 300 seconds.

How can I retrieve the other data? Any suggestions, please?
virothi 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
Pressure Inlet Boundary Condition for gas-solid fluidized bed m.uzair Fluent Multiphase 0 January 18, 2018 06:08
Question about adaptive timestepping Guille1811 CFX 25 November 12, 2017 17:38
Basic Nozzle-Expander Design karmavatar CFX 20 March 20, 2016 08:44
Question about heat transfer coefficient setting for CFX Anna Tian CFX 1 June 16, 2013 06:28
Error finding variable "THERMX" sunilpatil CFX 8 April 26, 2013 07:00


All times are GMT -4. The time now is 10:04.