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

How to write an UDF : polynomial equation as a source of energy

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 25, 2020, 13:09
Default How to write an UDF : polynomial equation as a source of energy
  #1
New Member
 
Chaatouf Dounia
Join Date: Jun 2019
Posts: 11
Rep Power: 6
Dounia is on a distinguished road
Hello everyone,

I'm trying to write a UDF (source term), I have a polynomial equation but I have no idea how to write it, I tried using DEFINE_SOURCE but it didn't work, please, can someone help me in this.

#include "udf.h"

#include<math.h>

DEFINE_SOURCE(Energy_source, c, ct, S, dS)

{

real source;

real flow_time;

real t = CURRENT_TIME;

{

if ((t>0)&&(t<39600))

{

source =((0.3179*pow((t/3600),4.0))-(8.4583*pow((t/3600),3.0))+(50.847*pow((t/3600),2.0))+(31.165*(t/3600))+327.88)*(0.81/0.001);

}

else

{

source=0;

}

}

return source;

}

I'll be so grateful for any help.

Best regards and best wishes,

Dounia
Dounia is offline   Reply With Quote

Old   February 25, 2020, 15:19
Default Polynomial
  #2
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
The expression is correct, however, there would be conflicts. First, do not use t as variable name. This is an internally defined variable. You can use flow_time that you already have in your code but not in use. So, set

real flow_time = CURRENT_TIME;

Secondly, all the values provided by the Fluent to the UDF and from the UDF to the Fluent are always in SI. Calculations can be done in any units within a UDF but while returning values to Fluent, the values have to be in SI. So, CURRENT_TIME is always in s. Therefore, you do not need to divide by 3600; if that is the reason you are dividing it by.

Thirdly, time is never negative. So, no need to mention t>0 since it always is.

Furthermore, since this is an energy source term, you need to take first derivative of the polynomial with respect to temperature and write it as

S[dS] = first derivative in term

Since in the current equation there is no temperature dependence, you can simply mention it as

S[dS] = 0.;
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   February 26, 2020, 12:25
Default
  #3
New Member
 
Chaatouf Dounia
Join Date: Jun 2019
Posts: 11
Rep Power: 6
Dounia is on a distinguished road
Thank you very much for answering me,
it doesn't give me an error anymore, I really appreciate it,
Best regards,
Dounia
Dounia is offline   Reply With Quote

Reply

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
[Other] Tabulated thermophysicalProperties library chriss85 OpenFOAM Community Contributions 62 October 2, 2022 03:50
[OpenFOAM.org] Error creating ParaView-4.1.0 OpenFOAM 2.3.0 tlcoons OpenFOAM Installation 13 April 20, 2016 17:34
[swak4Foam] funkySetFields compilation error tayo OpenFOAM Community Contributions 39 December 3, 2012 05:18
"parabolicVelocity" in OpenFoam 2.1.0 ? sawyer86 OpenFOAM Running, Solving & CFD 21 February 7, 2012 11:44
OpenFOAM on MinGW crosscompiler hosted on Linux allenzhao OpenFOAM Installation 127 January 30, 2009 19:08


All times are GMT -4. The time now is 06:54.