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

Problem with UDF - DEFINE_SPECIFIC_HEAT macro

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 1 Post By estevaotolentino
  • 1 Post By Svetlana
  • 2 Post By D.M

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 13, 2017, 13:47
Default Problem with UDF - DEFINE_SPECIFIC_HEAT macro
  #1
New Member
 
Estêvão Lannes Tolentino
Join Date: Oct 2016
Posts: 9
Rep Power: 10
estevaotolentino is on a distinguished road
Hi,

I'm having some problems with the DEFINE_SPECIFIC_HEAT macro. I need to vary the specific heat of a solid over time, where the equation that varies this property is in function of M (moisture content of a bed of grains). The variable M is defined outside of the DEFINE_SPECIFIC_HEAT macro (it is defined inside another macro called DEFINE_ADJUST), then I need to fetch this variable M through memory C_UDMI (c, t, 0), where M is stored in the UDM 0 memory. Here is my macro:

DEFINE_SPECIFIC_HEAT(specific_heat_paddy, T, Tref, h, yi)
{
real cp_paddy, M;
Thread *t;
cell_t c;
M = C_UDMI(c, t, 0);
cp_paddy = 1110 + 44.8 * (M / (M + 1));
*h = cp_paddy * (T - Tref);
return cp_paddy;
}

I'm interpreting the UDF. When I initialize the problem, an error message appears:

"Error: received a fatal signal (Segmentation fault).
Error Object: #f
/solve/initialize/initialize-flow"

Could anyone help me solve this problem? Thanks.
Svetlana likes this.
estevaotolentino is offline   Reply With Quote

Old   June 14, 2017, 21:15
Default Simplify?
  #2
Senior Member
 
Svetlana Tkachenko
Join Date: Oct 2013
Location: Australia, Sydney
Posts: 416
Rep Power: 15
Svetlana is on a distinguished road
Hi,

Maybe you want to try the simplification approach as outlined below

1. assign constant to both values.

DEFINE_SPECIFIC_HEAT(specific_heat_paddy, T, Tref, h, yi)
{
//real cp_paddy, M;
//Thread *t;
//cell_t c;
//M = C_UDMI(c, t, 0);
//cp_paddy = 1110 + 44.8 * (M / (M + 1));
// *h = cp_paddy * (T - Tref);

*h = 115.0; // sensible enthalpy
return 100.0; // specific heat
}

2. If this works, define variables M, c, t.

DEFINE_SPECIFIC_HEAT(specific_heat_paddy, T, Tref, h, yi)
{
real M;
//real cp_paddy, M;
Thread *t;
cell_t c;
//M = C_UDMI(c, t, 0);
//cp_paddy = 1110 + 44.8 * (M / (M + 1));
// *h = cp_paddy * (T - Tref);

*h = 115.0; // sensible enthalpy
return 100.0; // specific heat
}

3. If this works, assign a value to M.

DEFINE_SPECIFIC_HEAT(specific_heat_paddy, T, Tref, h, yi)
{
real M;
//real cp_paddy, M;
Thread *t;
cell_t c;
M = C_UDMI(c, t, 0);
//cp_paddy = 1110 + 44.8 * (M / (M + 1));
// *h = cp_paddy * (T - Tref);

*h = 115.0; // sensible enthalpy
return 100.0; // specific heat
}


4. Define cp_paddy


DEFINE_SPECIFIC_HEAT(specific_heat_paddy, T, Tref, h, yi)
{
//real M;
real cp_paddy, M;
Thread *t;
cell_t c;
M = C_UDMI(c, t, 0);
//cp_paddy = 1110 + 44.8 * (M / (M + 1));
// *h = cp_paddy * (T - Tref);

*h = 115.0; // sensible enthalpy
return 100.0; // specific heat
}

5. Assign a value to cp_paddy,

DEFINE_SPECIFIC_HEAT(specific_heat_paddy, T, Tref, h, yi)
{
//real M;
real cp_paddy, M;
Thread *t;
cell_t c;
M = C_UDMI(c, t, 0);
cp_paddy = 1110 + 44.8 * (M / (M + 1));
// *h = cp_paddy * (T - Tref);

*h = 115.0; // sensible enthalpy
return 100.0; // specific heat
}

6. Assign a value to h,

DEFINE_SPECIFIC_HEAT(specific_heat_paddy, T, Tref, h, yi)
{
//real M;
real cp_paddy, M;
Thread *t;
cell_t c;
M = C_UDMI(c, t, 0);
cp_paddy = 1110 + 44.8 * (M / (M + 1));
*h = cp_paddy * (T - Tref);
// *h = 115.0; // sensible enthalpy
return 100.0; // specific heat
}

7. Start returning cp_paddy instead of the constant,

DEFINE_SPECIFIC_HEAT(specific_heat_paddy, T, Tref, h, yi)
{
//real M;
real cp_paddy, M;
Thread *t;
cell_t c;
M = C_UDMI(c, t, 0);
cp_paddy = 1110 + 44.8 * (M / (M + 1));
*h = cp_paddy * (T - Tref);
// *h = 115.0; // sensible enthalpy
return cp_paddy; // specific heat
}
estevaotolentino likes this.
Svetlana is offline   Reply With Quote

Old   June 15, 2017, 03:39
Default
  #3
D.M
Member
 
Davoud Malekian
Join Date: Jan 2016
Posts: 53
Rep Power: 10
D.M is on a distinguished road
Quote:
Originally Posted by estevaotolentino View Post
Hi,

I'm having some problems with the DEFINE_SPECIFIC_HEAT macro. I need to vary the specific heat of a solid over time, where the equation that varies this property is in function of M (moisture content of a bed of grains). The variable M is defined outside of the DEFINE_SPECIFIC_HEAT macro (it is defined inside another macro called DEFINE_ADJUST), then I need to fetch this variable M through memory C_UDMI (c, t, 0), where M is stored in the UDM 0 memory. Here is my macro:

DEFINE_SPECIFIC_HEAT(specific_heat_paddy, T, Tref, h, yi)
{
real cp_paddy, M;
Thread *t;
cell_t c;
M = C_UDMI(c, t, 0);
cp_paddy = 1110 + 44.8 * (M / (M + 1));
*h = cp_paddy * (T - Tref);
return cp_paddy;
}

I'm interpreting the UDF. When I initialize the problem, an error message appears:

"Error: received a fatal signal (Segmentation fault).
Error Object: #f
/solve/initialize/initialize-flow"

Could anyone help me solve this problem? Thanks.

i guess this error happens because of the first iteration and define_adjust, try to define your parameter M with the define_execute_at_end and see if the error happens again,
Svetlana and estevaotolentino like this.
D.M is offline   Reply With Quote

Old   June 20, 2017, 22:24
Default
  #4
New Member
 
Estêvão Lannes Tolentino
Join Date: Oct 2016
Posts: 9
Rep Power: 10
estevaotolentino is on a distinguished road
Thank you for the reply D.M and Светлана. I tried what you suggested, but that did not solve my problem.

I sent a message to Ansys support and received the following response: "The DEFINE_SPECIFIC_HEAT macro does not allow as much customization as the DEFINE_PROPERTY function. There is no way to fetch a cell value in the DEFINE_SPECIFIC_HEAT macro, unfortunately."

There is also a similar question on the Ansys support portal. Following is the answer from Ansys:

"Why is the cell data not available in the DEFINE_SPECIFIC_HEAT UDF?
The UDF for specific heat is called as part of the material definition in the solver where the cell is not available. This is a limitation for this macro and its Real Gas equivalent.
Cp is by definition ∂H/∂T, so for it to have other dependencies is not expected by the solver. Since Cp and enthalpy definitions are critical to the stability of the energy equation, a strict format has to be defined so that the UDF doesn't cause instabilities.The only way to vary the Cp at the cell level is via the variation of the mass fractions of a mixture. This is what most users are trying to emulate when they are using a UDS, UDM or similar value to vary Cp. They should instead add a new species (which is not much more expensive than a UDS) to follow the material flow. The species could be a copy of the original species, but with a different Cp. Then, the Cp can be varied by varying the proportions of the species, potentially via source terms driven by UDM values."
estevaotolentino is offline   Reply With Quote

Old   April 3, 2019, 16:01
Default
  #5
m__
New Member
 
Join Date: Jan 2019
Posts: 1
Rep Power: 0
m__ is on a distinguished road
Quote:
Originally Posted by estevaotolentino View Post
"Why is the cell data not available in the DEFINE_SPECIFIC_HEAT UDF?
The UDF for specific heat is called as part of the material definition in the solver where the cell is not available. This is a limitation for this macro and its Real Gas equivalent.
Cp is by definition ∂H/∂T, so for it to have other dependencies is not expected by the solver. Since Cp and enthalpy definitions are critical to the stability of the energy equation, a strict format has to be defined so that the UDF doesn't cause instabilities.The only way to vary the Cp at the cell level is via the variation of the mass fractions of a mixture. This is what most users are trying to emulate when they are using a UDS, UDM or similar value to vary Cp. They should instead add a new species (which is not much more expensive than a UDS) to follow the material flow. The species could be a copy of the original species, but with a different Cp. Then, the Cp can be varied by varying the proportions of the species, potentially via source terms driven by UDM values."

estevaotolentino, did you end up using the species method they suggested? I am running into a similar limitation to you with my analysis and this seems like the only way I can resolve it
m__ 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
UDF Problem about Grid Motion !!! Zhengyu Gao Fluent UDF and Scheme Programming 0 December 6, 2013 20:45
Mesh UDF problem kornetka Fluent UDF and Scheme Programming 4 July 25, 2013 07:54
fluent udf problem: write specific data for every iteration in a file. nnvoro Fluent UDF and Scheme Programming 1 May 27, 2013 16:26
UDF using problem, error happens-heip!! Michael FLUENT 1 December 9, 2008 08:51
UDF variables F1, y / problem with UDF Fabian FLUENT 6 June 2, 2003 11:22


All times are GMT -4. The time now is 01:32.