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

how to write udf for a component source term on a wall ?

Register Blogs Community New Posts Updated Threads Search

Like Tree9Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 13, 2019, 04:33
Default
  #21
Member
 
Vignesh Lakshmanan
Join Date: Nov 2016
Posts: 79
Rep Power: 10
ViLaks is on a distinguished road
Quote:
Originally Posted by Hasan_Najafi View Post
Dear Vignesh,

The “dS[eqn]=0;” is derivative of the source term with respect to the temperature (for the energy source term in your UDF). This line can enhance the stability of the solution and help convergence rates due to the increase in diagonal terms on the solution matrix. For more information about it, you can see the ANSYS FLUENT UDF Manual (there is an example for the source term that you can understand the argument's type of this Macro easily).
To make the correlation between the temperature and position of “x”; if your temperature changes as a function of position, you can write your source term by using these lines.

real x[ND_ND], xx, yy, zz;
C_CENTROID(x,c,t);
xx=x[0]; //x-position
yy=x[1]; //y-position
zz=x[2]; //z-position



Best regard
Hasan Najafi Khaboshan
Dear Hasan,

Thanks for your swift reply. Sorry, I confused you. By "x", I didnt mean position. Its difficult to explain in words. But I understood the part and I will try to workout the problem.

Regards
Vignesh
ViLaks is offline   Reply With Quote

Old   October 8, 2021, 07:34
Default Wall Surface Reactions
  #22
New Member
 
Ugur Goktolga
Join Date: Jul 2013
Posts: 4
Rep Power: 13
mugurg is on a distinguished road
I think the problem in the original question could've been solved without any UDF. In Fluent, you can also specify wall surface reactions, and then define your reaction rate constants. By playing with the reaction rate constants (Pre-exponential term, activation energy and temperature exponent), you can get your desired reaction rates I believe.
mugurg is offline   Reply With Quote

Old   January 17, 2022, 11:34
Default
  #23
New Member
 
Joe
Join Date: Jan 2022
Posts: 13
Rep Power: 4
CFD27 is on a distinguished road
Hi all,
I would like to implement a source in the cell row that is adjacent to a wall and
I think the UDF of Hasan_Najafi is a good approach for this.
I have already compiled the UDF without error, but I cannot execute the UDF on demand in Fluent, because Fluent does not respond when I want to execute the UDF in the "Execute on Demand" dialog box.
Any suggestion would be helpful.
Many greetings
Joe
CFD27 is offline   Reply With Quote

Old   January 19, 2022, 04:06
Default
  #24
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
can you execute on_demand macro in case there is only Message("text"); function inside?

Code:
#include "udf.h"
DEFINE_ON_DEMAND(test)
{
Message("text");
}
__________________
best regards


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

Old   January 19, 2022, 04:29
Default
  #25
New Member
 
Joe
Join Date: Jan 2022
Posts: 13
Rep Power: 4
CFD27 is on a distinguished road
Dear Alexander,

Thank you for your reply. As in the UDF of Hasan_Najafi I used the UDM to mark the cells adjacent to the wall.
In the meantime, I checked if the UDF saves the values of the UDM to the cells on the wall.
This is the case. Now I have the question, what can be the reason, that nevertheless the source is not implemented.
The code looks like the following:

Code:

#include "udf.h"

DEFINE_ON_DEMAND(selecting_cell)
{
#if !RP_HOST
Domain *d;
Thread *t, *tc, *t0;
face_t f;
cell_t c, c0;
d = Get_Domain(1);

tc = Lookup_Thread(d, 8);

thread_loop_c(t, d)
{
begin_c_loop(c, t)
{
C_UDMI(c, t, 0) = 0;
}
end_c_loop(c,t)
}
begin_f_loop(f, tc)
{
c0 = F_C0(f, tc);
t0 = THREAD_T0(tc);
C_UDMI(c0, t0, 0) = 1;
}
end_f_loop(f,tc)
#endif
}
DEFINE_SOURCE(energy_source, c, t, dS, eqn)
{
real source;
if (C_UDMI(c, t, 0) > 0)
{
source = 1000.0;
dS[eqn] = 0.0;
}
else
{
source = 0.0;
dS[eqn] = 0.0;
}
return source;
}

Thank you in advance.
Many greetings
Joe
CFD27 is offline   Reply With Quote

Old   January 19, 2022, 04:41
Default
  #26
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
check values of udm_0 in your domain, it must be 1 near the wall with ID = 8
__________________
best regards


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

Old   January 19, 2022, 04:58
Default
  #27
New Member
 
Joe
Join Date: Jan 2022
Posts: 13
Rep Power: 4
CFD27 is on a distinguished road
Dear Alexander,
Thank you for your reply.
I checked the values of the UDM in the cells adjacent to the wall and instead of 1, they are 0.5. Shouldn't this work with 0.5?
Thanks
Many greetings
Joe
Hasan_Najafi likes this.
CFD27 is offline   Reply With Quote

Old   January 20, 2022, 00:42
Default
  #28
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
its not possible to have 0.5 as you have only 0 or 1 in your code.
this is error of plotting:
turn off node values while making the contour.

however, as you can see something except 0, means udf works, so source is applied also.
1000 means 1000W/m3. check if it enough to get some effect for your case
CFD27 likes this.
__________________
best regards


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

Old   January 20, 2022, 07:07
Default
  #29
New Member
 
Joe
Join Date: Jan 2022
Posts: 13
Rep Power: 4
CFD27 is on a distinguished road
Dear Alexander,

Thank you for your answer. I have issued the node values and am now getting values of 1.
Additionally, I have separated the UDF's.
Both UDF' I have compiled with no errors.
The DEFINE_SOURCE UDF I have hooked in the desired fluid domain and the DEFINE_ON_DEMAND UDF I have executed on demand.
Now the source UDF works as well.
But the question arises why not both UDF could be executed on demand.
Shouldn't this also work?

Many thanks in advance.
Many greetings
Joe
CFD27 is offline   Reply With Quote

Old   January 20, 2022, 22:03
Default
  #30
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
Quote:
Originally Posted by CFD27 View Post
But the question arises why not both UDF could be executed on demand.
Shouldn't this also work?
On_demand and define_source are two separated functions predefined in fluent structure. It's not possible to execute one fluent function from another.

On_demand is eceuted manually by user from fluent GUI
define_source returns some value to specified zone, is executed before each time step automatically
Hasan_Najafi and CFD27 like this.
__________________
best regards


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

Old   January 21, 2022, 03:10
Default
  #31
New Member
 
Joe
Join Date: Jan 2022
Posts: 13
Rep Power: 4
CFD27 is on a distinguished road
Quote:
On_demand and define_source are two separated functions predefined in fluent structure. It's not possible to execute one fluent function from another.

On_demand is eceuted manually by user from fluent GUI
define_source returns some value to specified zone, is executed before each time step automatically
Thank you for your reply. I had assumed that both are executed together. Then I found the problem. Thank you for your help.
Many greetings
Joe
CFD27 is offline   Reply With Quote

Old   February 13, 2022, 17:28
Default
  #32
New Member
 
DhyaniBaba
Join Date: Aug 2019
Posts: 23
Rep Power: 7
pdhyani96 is on a distinguished road
Quote:
Originally Posted by Hasan_Najafi View Post
Dear Vignesh,

I think the below UDF will help you.
First, you should mark your appropriate cells near the boundary condition by defining the UDM as DEFINE_ON_DEMAND Macro. Then, you can use it as an “if” statements in your source term. It should be noted that this UDF must be compiled and will be just run in parallel cases. I hope this UDF could help you.

Best regard
Hasan Najafi Khaboshan

Code:
#include "udf.h"

DEFINE_ON_DEMAND(selecting_the_cells)
{
	#if !RP_HOST
		Domain *d;
		Thread *t, *tc, *t0;
		face_t f;
		cell_t c, c0;
		d=Get_Domain(1);
		tc=Lookup_Thread(d,9); //thread pointer of the surface (the ID can be obtained from the boundary condition panel)
		//Loop through all the cell threads in the domain
		thread_loop_c(t,d)
		{
			//Loop through the cells in each cell thread
			begin_c_loop(c,t)
			{
				C_UDMI(c,t,0)=0;	
			}
			end_c_loop(c,t)
		}
		
		begin_f_loop(f,tc)
		{
			c0=F_C0(f,tc);
			t0=THREAD_T0(tc);
			C_UDMI(c0,t0,0)=1;
		}
		end_f_loop(f,tc)
	#endif
}

DEFINE_SOURCE(energy_source, c, t, dS, eqn)
{
	real source;
	if (C_UDMI(c,t,0)>0.)
	{
		source=1000.;
		dS[eqn]=0.;
	}
	else
	{
		source=0.;
		dS[eqn]=0.;
	}
	return source;
}
Hello,
I am doing a similar problem, where I apply a mass flow source term at an inlet boundary. I came across your UDF, although I am a bit confused on how to implement it? After I interpret the code, I see two UDFs loaded in Fluent, one is for selecting_the_cells, and the other is energy_source. How do I apply these UDFs, and where?

Secondly, I am just starting to work with UDFs, so I am having trouble understanding the syntax, and following the manual is not trivial for me as of now. Could you please shed some light on the syntax?

Thanks,
Priyank
pdhyani96 is offline   Reply With Quote

Old   February 15, 2022, 23:24
Default
  #33
New Member
 
Hasan Najafi Khaboshan
Join Date: Jan 2018
Posts: 11
Rep Power: 8
Hasan_Najafi is on a distinguished road
Quote:
Originally Posted by pdhyani96 View Post
Hello,
I am doing a similar problem, where I apply a mass flow source term at an inlet boundary. I came across your UDF, although I am a bit confused on how to implement it? After I interpret the code, I see two UDFs loaded in Fluent, one is for selecting_the_cells, and the other is energy_source. How do I apply these UDFs, and where?

Secondly, I am just starting to work with UDFs, so I am having trouble understanding the syntax, and following the manual is not trivial for me as of now. Could you please shed some light on the syntax?

Thanks,
Priyank
Hi. This UDF code has been generated for parallel processing. So, you should launch with a parallel solver. You should compile the UDF. I give you some steps below to compile this UDF.

1. Set the ID number (in Line 11) of your inlet boundary in the UDF and save it with a filename.c.
2. Launch with a parallel solver.
3. Set one User-defined memory in your case (User Define>Memory>set 1 for Number of User-Defined Memory Location).
4. Compile the UDF.
5. Set the UDF of your source term in Cell Zone conditions.
6. Initialize your case. I think if you hook the Execute on Demand and after that Initialize your case, the data of UDM will be gone.
7. Hook Execute on Demand (User Define>Execute on Demand button>chose the name of Execute on Demand UDF "selecting_the_cells">click OK). Also, you can plot the contour of UDM before running your case to check.
8. Then you can run your solver.

Let me know if you need more help.
Hope you run your case file.

Best regards,
Hasan Najafi Khaboshan
Hasan_Najafi is offline   Reply With Quote

Old   April 29, 2022, 03:08
Default
  #34
New Member
 
București
Join Date: Jan 2021
Posts: 3
Rep Power: 5
alexandraene is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
check values of udm_0 in your domain, it must be 1 near the wall with ID = 8
Hello! I kind of face the same issue here. I have used the same code in which I have added the "Message("%e\n", C_UDMI(c0,t0,0))" in order to check if the values for the cells 0 and 1 are implemented. After I compile and run the Define_On Demand macro I receive a message with the numbers of cells with 0 and 1. Nonetheless, the source term is implemented as 0 everywhere. I checked the UDM contour and it seems that all cell values are 0. Could you please be so kind and give me an idea on what I am doing wrong? This will be highly appreciated!
alexandraene is offline   Reply With Quote

Old   May 1, 2022, 01:26
Default
  #35
New Member
 
Hasan Najafi Khaboshan
Join Date: Jan 2018
Posts: 11
Rep Power: 8
Hasan_Najafi is on a distinguished road
Quote:
Originally Posted by alexandraene View Post
Hello! I kind of face the same issue here. I have used the same code in which I have added the "Message("%e\n", C_UDMI(c0,t0,0))" in order to check if the values for the cells 0 and 1 are implemented. After I compile and run the Define_On Demand macro I receive a message with the numbers of cells with 0 and 1. Nonetheless, the source term is implemented as 0 everywhere. I checked the UDM contour and it seems that all cell values are 0. Could you please be so kind and give me an idea on what I am doing wrong? This will be highly appreciated!
Hi, it would be better to check the UDM by plotting the contour. Note that, turn off node values while making the contour.
You should set the UDM, then interpret the Define_On Demand and check the contour.
Hasan_Najafi is offline   Reply With Quote

Reply

Tags
mass source udf, wall 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
mesh file for flow over a circular cylinder Ardalan Main CFD Forum 7 December 15, 2020 14:06
polynomial BC srv537 OpenFOAM Pre-Processing 4 December 3, 2016 10:07
[swak4Foam] Error bulding swak4Foam sfigato OpenFOAM Community Contributions 18 August 22, 2013 13:41
[swak4Foam] build problem swak4Foam OF 2.2.0 mcathela OpenFOAM Community Contributions 14 April 23, 2013 14:59
DxFoam reader update hjasak OpenFOAM Post-Processing 69 April 24, 2008 02:24


All times are GMT -4. The time now is 18:16.