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

UDF gives different values than calculated manually

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 27, 2016, 14:00
Default UDF gives different values than calculated manually
  #1
New Member
 
Join Date: Nov 2015
Posts: 4
Rep Power: 11
RebeccaKn92 is on a distinguished road
Hey!

I have a problem. I wrote an UDF for the density as a function of the enthalpy.

That is the source code:

#include "udf . h"

DEFINE_PROPERTY(density_dependent_on_enthalpy, cell, thread)
{
real cell_dens;
real enth = C_H(cell, thread);
real enth_adjusted = enth + 226110;

if (enth_adjusted > 427.25e3)
cell_dens = 115.74;
else if(enth_adjusted > 213.27e3)
cell_dens = −3.63730e−3*enth_adjusted + 1.669777515e+3;
else
cell_dens = 894.05;
return cell_dens;
}

I had to adjust the enthalpy due to different reference values.

Now everything works fine, but I wanted to proof that my UDF is working correctly. So I took the cell enthalpy from ANSYS via a XY-Plot and calculated the density values manually. And they are a little diffrent to the values ANSYS gave me.

I did the same with the viscosity as a function of the enthalpy and there ANSYS didn't even respect the borders of the enthalpy. I had a visosity of 16,7 with an enthalpy of 427,587e3 eventhough I implemented that above an enthalpy of 427,25e3 the viscosity should be 15,4.

How is that possible? I mean ANSYS is doing the same math as I did, right?

I don't understand, please help!
RebeccaKn92 is offline   Reply With Quote

Old   January 27, 2016, 17:52
Default
  #2
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Your UDF modifies the cell density, so we'll focus on that first. What are the enthalpies before and after the UDF is called on a cell, and how do these values compare to your hand calculations? You could copy your UDF to a DEFINE_ON_DEMAND macro and run on a single cell for debugging purposes.

Note: DEFINE_PROPERTY is called at each iteration for each cell, therefore the calculated density will be different at each time step if the solution is still converging. Also, Fluent calculates values for cells and if you've created an XY-plot with nodal values then you should expect interpolation errors (probably small but would still be different).
`e` is offline   Reply With Quote

Old   January 28, 2016, 05:14
Default
  #3
New Member
 
Join Date: Nov 2015
Posts: 4
Rep Power: 11
RebeccaKn92 is on a distinguished road
At first: Thank you so much for your quick reply!!

I don't know what the value of the enthalpy is before the UDF is called on. How do I find out?

The good thing is: This is a study project, so I don't have to fix the problem, I just have to explain why the values are different. My first idea was that ANSYS first calls on property values of the flowing fluid to calculate temperature, enthalpy and everthing else.
Then the UDF wants to know the enthalpy, which isn't calculated for this cell yet, so it takes the enthalpy of the cell before. After setting the density it calculates the enthalpy for the cell and this is the enthalpy ANSYS shows me in the XY-Plot, which with I calculate.

Could that be the possible? Or does ANSYS calculates the other way around?

So you mean because ANSYS calculates with the cell values and I looked up the node values and calculated with those, that is why there is a difference? Do I understand correctly?

I am sorry if my questions are a bit confusing, I am not the best in CFD but I am trying my best!
RebeccaKn92 is offline   Reply With Quote

Old   February 1, 2016, 06:03
Default
  #4
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Quote:
Originally Posted by RebeccaKn92 View Post
I don't know what the value of the enthalpy is before the UDF is called on. How do I find out?
Use the DEFINE_ON_DEMAND macro for this debugging process: print the ethalpy to the screen before and after your UDF modifies the enthalpy. Select either a single cell or small region within your domain (restrict with conditional statements) to avoid excessive messages printed on your screen. For example:

Code:
DEFINE_ON_DEMAND(debugging_enthalpy)
{
	Domain *d = Get_Domain(1);
	Thread *t;
	cell_t c;
	real x[ND_ND], enth_adjusted, cell_dens;

	thread_loop_c(t,d)
	{
		begin_c_loop_int(c,t)
		{
			C_CENTROID(x,c,t);

			if (x[0] > 1. && x[1] > 1. && x[2] > 1.) // cells only outside x > 1 etc
			//if (c == 0) // alternatively select a specific cell only
			{
				Message("Before: this cell (ID: %d) has an enthalpy = %e [J] and density = %e [kg/m^3].\n",c,C_H(c,t),C_R(c,t));
				
				enth_adjusted = C_H(c,t) + 226110.;

				if (enth_adjusted > 427.25e3)
					cell_dens = 115.74;
				else if (enth_adjusted > 213.27e3)
					cell_dens = −3.63730e−3*enth_adjusted + 1.669777515e+3;
				else
					cell_dens = 894.05;
				
				Message("After: this cell (ID: %d) has an enthalpy = %e [J] and density = %e [kg/m^3].\n",c,enth_adjusted,cell_dens);
			}
		}
		end_c_loop_int(c,t)
	}
}
Quote:
Originally Posted by RebeccaKn92 View Post
The good thing is: This is a study project, so I don't have to fix the problem, I just have to explain why the values are different. My first idea was that ANSYS first calls on property values of the flowing fluid to calculate temperature, enthalpy and everthing else.
Then the UDF wants to know the enthalpy, which isn't calculated for this cell yet, so it takes the enthalpy of the cell before. After setting the density it calculates the enthalpy for the cell and this is the enthalpy ANSYS shows me in the XY-Plot, which with I calculate.

Could that be the possible? Or does ANSYS calculates the other way around?
User-defined properties, such as your enthalpy dependent density function, are called when the properties are updated (after the mass and momentum equations are solved). The enthalpy is associated with the energy equation and is solved after the mass/momentum and before the properties update.

Quote:
Originally Posted by RebeccaKn92 View Post
So you mean because ANSYS calculates with the cell values and I looked up the node values and calculated with those, that is why there is a difference? Do I understand correctly?
There may be small interpolation errors between node and cell values but these differences shouldn't be significant.
`e` is offline   Reply With Quote

Old   February 6, 2016, 12:29
Default
  #5
New Member
 
Join Date: Nov 2015
Posts: 4
Rep Power: 11
RebeccaKn92 is on a distinguished road
Thank you so much for your help!

Because of the fact that the due date for my paper is monday, I tried to explain the errors as good as possible.

I am very thankful for your explanations, now I understand everything way better! You really saved my work!
RebeccaKn92 is offline   Reply With Quote

Reply

Tags
ansys, density, fluent, 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
dsmcFoam setup hherbol OpenFOAM Pre-Processing 1 November 19, 2021 02:52
UDF for reading file and assigning temperature values to boundary faces Sherlock_1812 Fluent UDF and Scheme Programming 7 June 13, 2016 10:20
Eulerian Wall Film Model - how to use calculated values in UDF? marie Fluent Multiphase 0 June 24, 2015 09:33
I need UDF help. S.Whitney FLUENT 0 October 15, 2007 12:29
udf language + UDMI values chary FLUENT 0 October 5, 2007 07:58


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