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

Having difficulties writing UDF program for calculating the source term

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 6, 2015, 02:22
Default Having difficulties writing UDF program for calculating the source term
  #1
New Member
 
Join Date: Dec 2015
Posts: 11
Rep Power: 10
fersim is on a distinguished road
Good morning,
Please help me to write a UDF program for calculate the source term
If Temperature at time (t) > Temperature at time (t-1) and If Temperature at time (t) > 30 and Temperature at time (t-1) < 20
S= 5*rho* T/delta t
If Temperature at time (t) > Temperature at time (t-1) and Temperature at time (t) <30 and Temperature at time (t-1) < 5
S= 2*rho* T/delta t
If Temperature at time (t) < Temperature at time (t-1) and Temperature at time (t) = 30 and Temperature at time (t-1) < 5
S= rho* T/delta t
If Temperature at time (t) = Temperature at time (t-1)
S = S at (t-1)
Where:
delta t = time at (t) – time at (t-1)
and T is temperature Calculated by Fluent.

Thank you.

My program is :

#include "udf.h"
#define S_0
#define rho 100
DEFINE_SOURCE(terme_source, cell, thread, dS, eqn);
{
real T_t = C_T(c,t);
reat T_t_1 = C_T_M1(c,t);
real delta_time = CURRENT_TIMESTEP;
reat prev_time = PREVIOUS_TIME;
time = CURRENT_TIME;
real source;
If (T_t > T_t_1 && T_t > 30 && T_t_1 < 20)
{
source = 5*rho*T_t/ CURRENT_TIMESTEP;
}
else if (T_t >T_t_1 && T_t < 30 && T_t_1 < 5)
{
source = 2*rho*T_t/ CURRENT_TIMESTEP;
}
else if (T_t<T_t_1 && T_t = 30 && T_t_1 < 5)
{
source = rho*T_t/ CURRENT_TIMESTEP;
}
else T_t = T_t_1;
{
source = S_previous
}
return source;
}

Last edited by fersim; December 6, 2015 at 03:00. Reason: correction
fersim is offline   Reply With Quote

Old   December 7, 2015, 08:02
Default
  #2
Senior Member
 
Bruno
Join Date: Mar 2009
Location: Brazil
Posts: 277
Rep Power: 21
brunoc is on a distinguished road
All you have are small C errors which the compiler will show you.
  • Your first If should be written if (lowercase)
  • Your last else must have no condition
  • Equality conditions use double equal signs (T_1 == T_t_1)
  • You should set dS[eqn] to the temperature derivative of your source.
brunoc is offline   Reply With Quote

Old   December 7, 2015, 08:33
Default Udf
  #3
New Member
 
Join Date: Dec 2015
Posts: 11
Rep Power: 10
fersim is on a distinguished road
Thank you for your reply, but I have other problem. how to program C_T(c,t) >C_T_M1(c,t) in any program UDF, like DEFINE_SOURCE(terme_source, c, t, dS, eqn). Thank you.
fersim is offline   Reply With Quote

Old   December 7, 2015, 08:44
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
In the way that you did, but with the changes that brunoc suggested. If this is not what you need, please be more detailed in what your question really is...
pakk is offline   Reply With Quote

Old   December 7, 2015, 11:24
Default udf
  #5
New Member
 
Join Date: Dec 2015
Posts: 11
Rep Power: 10
fersim is on a distinguished road
I rephrase the problem as follows:
If Temperature at time (t) > Temperature at time (t-delta t)
Source(t) = 50000
If Temperature at time (t) > Temperature at time (t-delta t)
Source(t) = 10000
If Temperature at time (t) = Temperature at time (t-delta t)
Source(t)= Source_previous(t-dt)
If Temperature at time (t) = Temperature at time (t-delta t)
Source (t) = S (t - delta t)




#include "udf.h"
DEFINE_SOURCE(terme_source, c, t, dS, eqn)
{
real source;
real sourrce_previous; /*sourrce_previous= source at t=t-delta t */
if (C_T(c,t)>C_T_M1(c,t))
source = 50000;
else if (C_T(c,t)<C_T_M1(c,t))
source = 10000;
else
source = sourrce_previous;
dS[eqn]=0;
return source;
}
fersim is offline   Reply With Quote

Old   December 7, 2015, 11:35
Default
  #6
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
If you want to explain what your problem is, you need to write a little bit more text, not just a set of equations and some code.

Your set of equations more or less describe what you want to have. (But you mixed up some signs like > and <. Be careful, I can understand what it should be, but if you make such mistakes when you talk to Fluent, Fluent will misunderstand.) And then you put some code. What is that? You give the code without warning or explanation. I have to guess it is your attempt at a solution. But you don't say anything about it... Does it work? Does it compile? Do you get warnings? Does it run? Do you get results? Do you get good results? Do you get bad results?

Which part is giving you the problems? Turning the equations into program code? Coupling this code to Fluent? Compiling? Running? Give us some context to work with...
pakk is offline   Reply With Quote

Old   December 7, 2015, 14:16
Default udf
  #7
New Member
 
Join Date: Dec 2015
Posts: 11
Rep Power: 10
fersim is on a distinguished road
Good evening,
I'll write the details of my project.
This source code calculation value of the source term to account for the phase change phenomenon of a material. As the temperature increases (T (t) > T (t-delta t) the material absorbs heat, so the source term is negative. And decreasing temperature (T (t) <T (t-delta t) the material releases heat, so the source term is positive and finally if the temperature remains constant (T (t) = T (t-delta t) the source term equal to the previous value (source at t - delta t).
This code takes into account the hysteresis of a no pure phase change material. That is to say, the source term is different during the heat absorption and release of heat. This source term is written as a polynomial equation (Source = A * T + B).
I inform you that I code is compiled during simulation but there is the following error:
Error:
FLUENT received fatal signal (ACCESS_VIOLATION)
1. Note exact events leading to error.
2. Save case/data under new name.
3. Exit program and restart to continue.
4. Report error to your distributor.
Error Object: ()

This error is caused that this problem does not recognize the temperature at time t delta-t.


#include "udf.h"
DEFINE_SOURCE(terme_source, c, t, dS, eqn)
{
real source;
real sourrce_previous; /*sourrce_previous= source at t-delta t */
if (C_T(c,t)>C_T_M1(c,t))
source = -5*C_T(c,t)-25;
else if (C_T(c,t)<C_T_M1(c,t))
source = 8*C_T(c,t)+15;
else
source = sourrce_previous;
dS[eqn]=0;
return source;
}

Last edited by fersim; December 8, 2015 at 04:18.
fersim is offline   Reply With Quote

Old   December 9, 2015, 09:51
Default
  #8
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
One problem is that you never define what "sourrce_previous" is... If your temperature happens to be the same as the time step before, Fluent tries to access this value but does not know what it is. But for that the solution is simple: if you don't want to change the source, do nothing!

Code:
#include "udf.h"
DEFINE_SOURCE(terme_source, c, t, dS, eqn)
{
  real source;
  if (C_T(c,t)>C_T_M1(c,t)) {
    source = -5*C_T(c,t)-25;
  } else if (C_T(c,t)<C_T_M1(c,t)) {
    source = 8*C_T(c,t)+15;
  }
    /* no else here: do nothing if they are equal */
  dS[eqn]=0;
  return source;
}
But if the error occured during initialization, it can be solved by first initializing without the UDF loaded, and load the UDF after that.
pakk is offline   Reply With Quote

Old   December 9, 2015, 14:05
Default
  #9
Senior Member
 
Bruno
Join Date: Mar 2009
Location: Brazil
Posts: 277
Rep Power: 21
brunoc is on a distinguished road
One possible problem is that C_T_M1 might not exist at t=0. Maybe your UDF should check if t=0 and take care of that.
brunoc 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 Source term problem natantyt FLUENT 2 May 15, 2018 21:40
[foam-extend.org] problem when installing foam-extend-1.6 Thomas pan OpenFOAM Installation 7 September 9, 2015 21:53
[swak4Foam] Error bulding swak4Foam sfigato OpenFOAM Community Contributions 18 August 22, 2013 12:41
[swak4Foam] funkySetFields compilation error tayo OpenFOAM Community Contributions 39 December 3, 2012 05:18
source term udf tas38 FLUENT 1 August 14, 2009 10:44


All times are GMT -4. The time now is 15:50.