How to write an UDF : polynomial equation as a source of energy
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 |
Polynomial
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.; |
Thank you very much for answering me,
it doesn't give me an error anymore, I really appreciate it, Best regards, Dounia |
All times are GMT -4. The time now is 14:26. |