CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (http://www.cfd-online.com/Forums/fluent-udf/)
-   -   UDF for a time varying temperature boundary condition (http://www.cfd-online.com/Forums/fluent-udf/124699-udf-time-varying-temperature-boundary-condition.html)

sparke03 October 11, 2013 03:12

UDF for a time varying temperature boundary condition
 
Hello,

I'm VERY new to Fluent and I'm attempting to write a UDF that will make the temperature at a wall a function of time. I've never programmed in C before either so I'm having some trouble getting the correct sytax.

Here's my UDF:

#include "udf.h"

DEFINE_PROFILE(HC_temp_BC,thread,i)
{
face_t f;
begin_f_loop(f,thread)
{
time=CURRENT_TIME;
F_PROFILE(f,thread,i)=(-4*10^(-17))*t^5 + (1*10^(-12))*t^4 - (1*10^(-8))*t^3 + (5*10^(-2))*t^2 - (0.0357*t)+304.5;
}
end_f_loop(f,thread)
}


I didn't compile it. I've been trying to use Fluent's interpreter but every time I try to interpret it I get this error:

"Error: /home/aero/Desktop/HC_temp.c: line 2: syntax error"

I'm sure the solution is very simple, but I'm a complete noob so I could use some help. Thanks!

ghost82 October 11, 2013 11:18

Quote:

Originally Posted by sparke03 (Post 456273)
Hello,

I'm VERY new to Fluent and I'm attempting to write a UDF that will make the temperature at a wall a function of time. I've never programmed in C before either so I'm having some trouble getting the correct sytax.

Here's my UDF:

#include "udf.h"

DEFINE_PROFILE(HC_temp_BC,thread,i)
{
face_t f;
begin_f_loop(f,thread)
{
time=CURRENT_TIME;
F_PROFILE(f,thread,i)=(-4*10^(-17))*t^5 + (1*10^(-12))*t^4 - (1*10^(-8))*t^3 + (5*10^(-2))*t^2 - (0.0357*t)+304.5;
}
end_f_loop(f,thread)
}


I didn't compile it. I've been trying to use Fluent's interpreter but every time I try to interpret it I get this error:

"Error: /home/aero/Desktop/HC_temp.c: line 2: syntax error"

I'm sure the solution is very simple, but I'm a complete noob so I could use some help. Thanks!

Sintax error refers to exponential "^'; right sintax is pow(x,y) which returns x raised to y;
try this:

Code:

#include "udf.h"

DEFINE_PROFILE(HC_temp_BC,thread,i)
{
face_t f;
begin_f_loop(f,thread)
{
time=CURRENT_TIME;
F_PROFILE(f,thread,i)=(-4*pow(10,-17))*pow(t,5)+pow(10,-12)*pow(t,4)-pow(10,-8)*pow(t,3)+5*pow(10,-2)*pow(t,2)-0.0357*t+304.5;
}
end_f_loop(f,thread)
}

Daniele

ghost82 October 11, 2013 11:25

But you have error on line 2?
Make sure you are writing in txt file, then rename .txt to .c and that there aren't "hidden" characters in line 2.

Daniele

sparke03 October 16, 2013 01:05

Thank you Ghost82. I've never coded in C before so I'd written the equation as if I were coding it in MATLAB. Thanks for correcting me!

I finally figured out why I was getting a sytax error on line 2. I had written the function on my PC (Windows), and then sent it to one of the university's computers (Linux) to run it in Fluent. I just rewrote the function on the Linux computer and it worked perfectly.


All times are GMT -4. The time now is 22:59.