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 Members List Search Today's Posts Mark Forums Read

Like Tree3Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 11, 2017, 23:48
Default how to write udf for a component source term on a wall ?
  #1
New Member
 
Join Date: Jul 2017
Posts: 13
Rep Power: 6
sami1991 is on a distinguished road
Hi
How can I include a component source term on a wall.
The source term udf in fluent is defined for volumetric zone.
Any suggestions will be very helpful.

Thank you
sami1991 is offline   Reply With Quote

Old   September 12, 2017, 04:10
Default
  #2
Senior Member
 
sbaffini's Avatar
 
Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 1,627
Blog Entries: 20
Rep Power: 33
sbaffini will become famous soon enoughsbaffini will become famous soon enough
Send a message via Skype™ to sbaffini
Can you elucidate on the concept of "source term on a wall"? Because that's not something typically present in the NS equations, so Fluent does not allow you to do it. If it is something specific to a certain model, you might find a FLUENT option in the specific section of the manual.
sbaffini is offline   Reply With Quote

Old   September 12, 2017, 06:06
Default
  #3
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 1,760
Rep Power: 28
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
You may apply heat flux to the wall:
1 way - use profile and apply flux as a table
2 way - use UDF and Define_profile function

Best regards
pejman_tork likes this.
AlexanderZ is offline   Reply With Quote

Old   September 12, 2017, 06:48
Default
  #4
Senior Member
 
sbaffini's Avatar
 
Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 1,627
Blog Entries: 20
Rep Power: 33
sbaffini will become famous soon enoughsbaffini will become famous soon enough
Send a message via Skype™ to sbaffini
Quote:
Originally Posted by AlexanderZ View Post
You may apply heat flux to the wall:
1 way - use profile and apply flux as a table
2 way - use UDF and Define_profile function

Best regards
Which goes under the "boundary condition" nomenclature (and Fluent section). That's why I asked for elucidation. Once we agree on the terminology we can go further with giving help.
sbaffini is offline   Reply With Quote

Old   September 14, 2017, 22:22
Default
  #5
New Member
 
Join Date: Jul 2017
Posts: 13
Rep Power: 6
sami1991 is on a distinguished road
Hi

I have a rectangular box, and on one wall of this box I want to generate water (all over the wall).
I was thinking to write a UDF on wall for mass source term. But mass source term can be applied on cell volume (mol/m3-sec) not on face cell (mol/m2-sec).
Can you please suggest something now ?
sami1991 is offline   Reply With Quote

Old   September 14, 2017, 22:23
Default
  #6
New Member
 
Join Date: Jul 2017
Posts: 13
Rep Power: 6
sami1991 is on a distinguished road
Quote:
Originally Posted by sbaffini View Post
Which goes under the "boundary condition" nomenclature (and Fluent section). That's why I asked for elucidation. Once we agree on the terminology we can go further with giving help.
Hi

I have a rectangular box, and on one wall of this box I want to generate water (all over the wall).
I was thinking to write a UDF on wall for mass source term. But mass source term can be applied on cell volume (mol/m3-sec) not on face cell (mol/m2-sec).
Can you please suggest something now ?
sami1991 is offline   Reply With Quote

Old   September 14, 2017, 22:27
Default
  #7
New Member
 
Join Date: Jul 2017
Posts: 13
Rep Power: 6
sami1991 is on a distinguished road
Quote:
Originally Posted by sbaffini View Post
Which goes under the "boundary condition" nomenclature (and Fluent section). That's why I asked for elucidation. Once we agree on the terminology we can go further with giving help.
One way is too select the cell volumes next to wall and apply the mass source term there.
But now , how to select the cell volumes there ? and how to convert the units, since it give mass generate rate in volume instead of surface?
sami1991 is offline   Reply With Quote

Old   September 15, 2017, 05:51
Default
  #8
Senior Member
 
sbaffini's Avatar
 
Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 1,627
Blog Entries: 20
Rep Power: 33
sbaffini will become famous soon enoughsbaffini will become famous soon enough
Send a message via Skype™ to sbaffini
Quote:
Originally Posted by sami1991 View Post
Hi

I have a rectangular box, and on one wall of this box I want to generate water (all over the wall).
I was thinking to write a UDF on wall for mass source term. But mass source term can be applied on cell volume (mol/m3-sec) not on face cell (mol/m2-sec).
Can you please suggest something now ?
One way to do this is:

1) Define a new UDM and, in a DEFINE_ON_DEMAND UDF, set it first, say, to -1 in all the cells (by looping on all cells of all cell threads). Then perform a loop on the boundary threads and, for your selected boundary, loop on the thread faces and set the UDM in the C0 cell to the relative cell face area.

2) Use a DEFINE_SOURCE UDF where only the cells with positive UDM have the source term applied, the others simply return 0.

However, you need to know your model, the physical meaning of the source term and how it shoud be defined. Then you can simply scale it via the cell volume and the face area you stored in the UDM.

If you give more details (there are several ways to simulate water) maybe we can give more help.
sbaffini is offline   Reply With Quote

Old   September 15, 2017, 12:04
Default
  #9
New Member
 
Join Date: Jul 2017
Posts: 13
Rep Power: 6
sami1991 is on a distinguished road
Quote:
Originally Posted by sbaffini View Post
One way to do this is:

1) Define a new UDM and, in a DEFINE_ON_DEMAND UDF, set it first, say, to -1 in all the cells (by looping on all cells of all cell threads). Then perform a loop on the boundary threads and, for your selected boundary, loop on the thread faces and set the UDM in the C0 cell to the relative cell face area.

2) Use a DEFINE_SOURCE UDF where only the cells with positive UDM have the source term applied, the others simply return 0.

However, you need to know your model, the physical meaning of the source term and how it shoud be defined. Then you can simply scale it via the cell volume and the face area you stored in the UDM.

If you give more details (there are several ways to simulate water) maybe we can give more help.
I have a rectangular box in which upper and lower boundaries are wall and no reaction happening there and no mass flux. Specified mass fraction of H2 is given at front wall, and its diffusing through the rectangular box. Now at the back wall H2 is consumed and H2O get generated (its surface reaction, at the back wall), since only hydrogen is diffusing in the box, so in case I try to define chemical reaction there, it gives mass imbalance. So I wanted to introduce mass sink and mass source term at wall.
And, source term is volumetric, so how can I write a mass source term at wall ?
And, if there is way by considering the cells next to walls, then how to do it so source term units remains unchanged.
I hope problem statement is clear now. Any help will be much appreciated
sami1991 is offline   Reply With Quote

Old   September 18, 2017, 08:04
Default
  #10
Senior Member
 
sbaffini's Avatar
 
Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 1,627
Blog Entries: 20
Rep Power: 33
sbaffini will become famous soon enoughsbaffini will become famous soon enough
Send a message via Skype™ to sbaffini
Ok, I assume then that you are using the species transport approach. If I understand what you wrote, you are saying that using surface reactions from species transport is not working in your case.

If this is the case, I first suggest to investigate more why this is not working straight out of the box. There is no trick that is going to work if that is a physical reason.

I cannot help on the physics. You are in charge for this.

So, let us assume the reason is not physical and this can be done. At this stage, you should have an expression for what you think should be the source formula to be used for each face of the right boundary. Now, the only thing you need to know is that for source terms Fluent has units of generation-rate/volume or, roughly, your source term will be interpreted as an additional term in the equations having the same units of the unsteady term.

In practice, for you, given you know your source term, this means that Fluent is going to multiply it by the cell volume (i.e., it is going to make the volume integral on the cell, according to the FV technique). If you want a surface flux then, probably, you want it to be face integrated, so you need to divide your source term by the cell volume and multiply it by the relative cell face area (the one you stored in the UDM).

However, this is, somehow, part of tyhe physics of the source term. It is up to you to establish if, say, you need multiplication by the cell face area.
sbaffini is offline   Reply With Quote

Old   September 22, 2017, 01:55
Default
  #11
New Member
 
Join Date: Jul 2017
Posts: 13
Rep Power: 6
sami1991 is on a distinguished road
https://www.dropbox.com/s/64u6v0s50t...20box.cas?dl=0
https://www.dropbox.com/s/cqd8bbjpuv...ctangle.c?dl=0
Hi, I think the problem was not clear. So I am attaching my case file here for your reference. In the geometry you can see, at wall-1, specified mass fraction of components given and at wall-2 ,3, and 4, there is no mass flux. The components (H2, H20 and CH4 are diffusing through the geometry) and H2 gets consumed at constant rate (0.03 mol/m2-sec)at wall-3 and H2O gets generated there at the same rate. So how to do it ?
I have written udf for that, and attached here for your reference. Please have a look. It would be great help if you can comment on that.

Quote:
Originally Posted by sbaffini View Post
Ok, I assume then that you are using the species transport approach. If I understand what you wrote, you are saying that using surface reactions from species transport is not working in your case.

If this is the case, I first suggest to investigate more why this is not working straight out of the box. There is no trick that is going to work if that is a physical reason.

I cannot help on the physics. You are in charge for this.

So, let us assume the reason is not physical and this can be done. At this stage, you should have an expression for what you think should be the source formula to be used for each face of the right boundary. Now, the only thing you need to know is that for source terms Fluent has units of generation-rate/volume or, roughly, your source term will be interpreted as an additional term in the equations having the same units of the unsteady term.

In practice, for you, given you know your source term, this means that Fluent is going to multiply it by the cell volume (i.e., it is going to make the volume integral on the cell, according to the FV technique). If you want a surface flux then, probably, you want it to be face integrated, so you need to divide your source term by the cell volume and multiply it by the relative cell face area (the one you stored in the UDM).

However, this is, somehow, part of tyhe physics of the source term. It is up to you to establish if, say, you need multiplication by the cell face area.
sami1991 is offline   Reply With Quote

Old   September 22, 2017, 04:35
Default
  #12
Senior Member
 
sbaffini's Avatar
 
Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 1,627
Blog Entries: 20
Rep Power: 33
sbaffini will become famous soon enoughsbaffini will become famous soon enough
Send a message via Skype™ to sbaffini
I honestly don't understand what is not clear from my side.

Sorry to be rude but, one thing is "I don't know how to do THIS with udf" and a completely different one is "I don't know how to use udf IN GENERAL".

You need to activate "Source term" under cell conditions and provide the right udf for each species (you need two udf).

Also, your udf can be ok as first attempt, just to see if everything is ok, but you need to be sure that the selected x[0] range correctly selects only the cell layer you are interested in.

I have no idea if the source term is correct or not. You need to look into the manual and see what are the units for the species (I guess mass fractions, so no units). Your resulting source term in the given cells will be [units of species] [units of density]/[units of time] x cell volume x numerical value of source term. Still, looking at the manual, my first attempt would have been to use surface reactions and not an udf.

I suggest to move to something simpler than species transport and reactions to start with udf. A simple exercise you can do is with a pipe with inlet and outlet, a single species and a mass source term on a certain set of cells. Then monitor the mass imbalance between inlet and outlet to see the effect of the numerical value of the source term.
sbaffini is offline   Reply With Quote

Old   September 3, 2019, 08:43
Default
  #13
New Member
 
Hasan Najafi Khaboshan
Join Date: Jan 2018
Posts: 5
Rep Power: 5
Hasan_Najafi is on a distinguished road
Quote:
Originally Posted by sbaffini View Post
One way to do this is:

1) Define a new UDM and, in a DEFINE_ON_DEMAND UDF, set it first, say, to -1 in all the cells (by looping on all cells of all cell threads). Then perform a loop on the boundary threads and, for your selected boundary, loop on the thread faces and set the UDM in the C0 cell to the relative cell face area.

2) Use a DEFINE_SOURCE UDF where only the cells with positive UDM have the source term applied, the others simply return 0.

However, you need to know your model, the physical meaning of the source term and how it shoud be defined. Then you can simply scale it via the cell volume and the face area you stored in the UDM.

If you give more details (there are several ways to simulate water) maybe we can give more help.
Dear Paolo Lampitella

I have the same problem and your suggestion was great. I know that we can add the source term with UDF to our simulation in FLUENT (cell centroid), and I done this. But, I want to change the velocity (normal velocity of wall) on the faces of the wall boundary condition. With your way, I have added my source term to the first cells of the wall boundary condition (as you said in this forum). I want to know that is there any way to change the velocity component (x,y,z-velocity) of the wall?
Hasan_Najafi is offline   Reply With Quote

Old   September 3, 2019, 08:55
Default
  #14
Senior Member
 
sbaffini's Avatar
 
Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 1,627
Blog Entries: 20
Rep Power: 33
sbaffini will become famous soon enoughsbaffini will become famous soon enough
Send a message via Skype™ to sbaffini
Dear Hasan,

I don't know if I understood correctly your problem, but fixing the wall velocity via UDF should be straightforward with a DEFINE_PROFILE UDF.

Unfortunately, I don't have anymore access to Fluent and the manual, so I'm not 100% sure if velocity components at wall can be assigned by UDF, but they should be.

Note, however, that any wall-normal component is removed by Fluent, if I recall correctly.


In constrast, there is nothing, in the approach I described, that prevents you from varying the wall normal velocity to be used in your source term. You can store it in a separate UDM or premultiplied with the face area in a single UDM. This should work if the velocity doesn't change with iterations/time steps.
sbaffini is offline   Reply With Quote

Old   September 4, 2019, 00:14
Default
  #15
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 1,760
Rep Power: 28
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
ansys fluent customization manual
DEFINE_PROFILE macro

best regards
AlexanderZ is offline   Reply With Quote

Old   September 4, 2019, 11:04
Default
  #16
New Member
 
Hasan Najafi Khaboshan
Join Date: Jan 2018
Posts: 5
Rep Power: 5
Hasan_Najafi is on a distinguished road
Quote:
Originally Posted by sbaffini View Post
Dear Hasan,

I don't know if I understood correctly your problem, but fixing the wall velocity via UDF should be straightforward with a DEFINE_PROFILE UDF.

Unfortunately, I don't have anymore access to Fluent and the manual, so I'm not 100% sure if velocity components at wall can be assigned by UDF, but they should be.

Note, however, that any wall-normal component is removed by Fluent, if I recall correctly.


In constrast, there is nothing, in the approach I described, that prevents you from varying the wall normal velocity to be used in your source term. You can store it in a separate UDM or premultiplied with the face area in a single UDM. This should work if the velocity doesn't change with iterations/time steps.
Thanks for your response (Paolo Lampitella and Alexander).

According to my project and what I studied in the Fluent Customization Manual, I can't use the DEFINE_PROFILE macro. So, I should consider the effect of wall faces to the first cells near the wall based on FVM.
Hasan_Najafi is offline   Reply With Quote

Old   November 8, 2019, 01:20
Default
  #17
Member
 
Vignesh Lakshmanan
Join Date: Nov 2016
Posts: 76
Rep Power: 6
ViLaks is on a distinguished road
Hi All,

I have an equation which describes the variation of Cooling Capacity with respect to evaporating temperature. I need to input this in cell zone conditions as a source term in Fluent, so that this can act as a sink and remove heat from the intended cell zone/domain. Can anyone help me on writing this udf?

More details of the simulation:
Problem: Thermal pull down of Deep Freezer
Simulation: 3d, transient, natural convection case

Thanks in advace,
Vignesh
ViLaks is offline   Reply With Quote

Old   November 9, 2019, 05:29
Default
  #18
New Member
 
Hasan Najafi Khaboshan
Join Date: Jan 2018
Posts: 5
Rep Power: 5
Hasan_Najafi is on a distinguished road
Quote:
Originally Posted by ViLaks View Post
Hi All,

I have an equation which describes the variation of Cooling Capacity with respect to evaporating temperature. I need to input this in cell zone conditions as a source term in Fluent, so that this can act as a sink and remove heat from the intended cell zone/domain. Can anyone help me on writing this udf?

More details of the simulation:
Problem: Thermal pull down of Deep Freezer
Simulation: 3d, transient, natural convection case

Thanks in advace,
Vignesh
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;
}
Hasan_Najafi is offline   Reply With Quote

Old   November 12, 2019, 23:58
Default
  #19
Member
 
Vignesh Lakshmanan
Join Date: Nov 2016
Posts: 76
Rep Power: 6
ViLaks 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;
}
Dear Hasan,
Thanks for your reply. I'm pretty new to Fluent udf. Can you pls tell me what is the meaning/how the following line works:
ds(eqn) = o;

The reason im asking is im not sure whether my equation (which is a profile) can fit in here.

Also, suppose my equation is ax2+bx+c, how can I correlate temperature with "x" ?

Thanks and Regards
Vignesh
ViLaks is offline   Reply With Quote

Old   November 13, 2019, 03:07
Default
  #20
New Member
 
Hasan Najafi Khaboshan
Join Date: Jan 2018
Posts: 5
Rep Power: 5
Hasan_Najafi is on a distinguished road
Quote:
Originally Posted by ViLaks View Post
Dear Hasan,
Thanks for your reply. I'm pretty new to Fluent udf. Can you pls tell me what is the meaning/how the following line works:
ds(eqn) = o;

The reason im asking is im not sure whether my equation (which is a profile) can fit in here.

Also, suppose my equation is ax2+bx+c, how can I correlate temperature with "x" ?

Thanks and Regards
Vignesh
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
Hasan_Najafi is offline   Reply With Quote

Reply

Tags
mass source udf, wall udf

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


All times are GMT -4. The time now is 13:17.