|
[Sponsors] |
UDF gives different values than calculated manually |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
January 27, 2016, 14:00 |
UDF gives different values than calculated manually
|
#1 |
New Member
Join Date: Nov 2015
Posts: 4
Rep Power: 10 |
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! |
|
January 27, 2016, 17:52 |
|
#2 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
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). |
|
January 28, 2016, 05:14 |
|
#3 |
New Member
Join Date: Nov 2015
Posts: 4
Rep Power: 10 |
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! |
|
February 1, 2016, 06:03 |
|
#4 | ||
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
Quote:
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:
There may be small interpolation errors between node and cell values but these differences shouldn't be significant. |
|||
February 6, 2016, 12:29 |
|
#5 |
New Member
Join Date: Nov 2015
Posts: 4
Rep Power: 10 |
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! |
|
Tags |
ansys, density, fluent, udf |
|
|
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 |