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

UDF wrong output for time variant temperature profile

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 15, 2018, 08:44
Default UDF wrong output for time variant temperature profile
  #1
New Member
 
Join Date: Dec 2017
Posts: 12
Rep Power: 8
Tomsho is on a distinguished road
Hi all,

I'm trying to simulate a simple sine wave for a temperature profile using UDF and FLUENT.

my profile is: T(t)=337 + sin(200*pi*t) - where T is the temperature and t is time.

here is the code i use (I interpret the code):


Quote:
#include "udf.h"

#define PI 3.141592654



DEFINE_PROFILE(temp_sinwt, thread, position)

{

real r[ND_ND]; /* this will hold the position vector */

real x;

real tim=CURRENT_TIME;
real t1=10*10^-3; /* period time in sec*/
real L=0.005;
real w=200*PI;
real amp=1;
real Tm=64+273;

face_t f;

begin_f_loop(f, thread)

{

F_CENTROID(r,f,thread);

x = r[0];
F_PROFILE(f, thread, position) = Tm + amp*sin(w*tim);
}

end_f_loop(f, thread)

}
Here is the BC graph in time:

https://imgur.com/a/GttWXH5

one can see that my amplitude should be +/- 1 K but it is different in the graph.

Do you guys know what am I doing wrong?

Thanks a lot,
Tom
Tomsho is offline   Reply With Quote

Old   October 15, 2018, 11:13
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Suppose that your boundary where you impose the BC is between the X's in this plot:


Code:
X---------X
|         |
And your mesh is divided into 4 parts:
Code:
X-x-x--x--X
|         |
Note that the corners (the X's) are part of two boundaries: the horizontal boundary with your UDF, and a horizontal boundary.


Now, if you specify temperature also on the horizontal boundary as 337 K, then at t=25 ms (the maximum), you have three nodes with a temperature of 338 K, and two nodes where the temperature is 338 or 337 K, depending on in which order the boundary conditions are applied.
So if you calculate the average based nodes, you would get something between 337 and 338 K, the exact value depending on your mesh. A finer mesh would give a value closer to 338 K.


So, do you have an isothermal boundary condition on your 'other' walls, and are you calculating the temperature from the node values? If so, this is the explanation.
pakk is offline   Reply With Quote

Old   October 15, 2018, 13:44
Default
  #3
New Member
 
Join Date: Dec 2017
Posts: 12
Rep Power: 8
Tomsho is on a distinguished road
Hi, thanks for the response.

my other walls has insulation condition.

are you calculating the temperature from the node values? - I don't know. How can I check this one?

thanks again
Tomsho is offline   Reply With Quote

Old   October 15, 2018, 17:15
Default
  #4
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 11
obscureed is on a distinguished road
Hi Timsho,

This isn't actually relevant to your code, because you do not actually use t1, but it is such an important point of basic programming that I have to mention it:

Code:
10*10^-3 /* wrong!!! */
does not do what you think it does! (Actually, it hurts my head to think about what it does in C.)

To get 'x to the power y', you would need 'pow(x,y)' (and you might need '#include "math.h"' at the start of the file). To get 'x to the power -3', you might as well type '1/(x*x*x)'. To get '7 times 10 to the power -3', you should type '7.e-3'. (I used 7 instead of 10 to make it clearer.) This is definitely the best way to do it. (Also, this is true in all the programming languages I can think of.)

As a very minor point, you will find that M_PI is already defined as a macro for pi (including a fully accurate double-precision value if you happen to need it).

Is it correct that you observe the correct frequency, and almost the correct amplitude but not quite? Well then, my guess is that you have applied this temperature at an inlet (or similar), and some of the heat has leaked out of the model by "inlet diffusion". I think inlet diffusion is discussed in the help files in the context of species. It also occurs by default for energy, but you can control this if you activate the energy equation by a TUI command such as "/def/mod/energy" -- you'll get a yes/no question to proceed and then a question about inlet diffusion/conduction. Please tell us if this is the correct answer!

Good luck!
Ed
obscureed 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
[openSmoke] libOpenSMOKE Tobi OpenFOAM Community Contributions 562 January 25, 2023 09:21
udf to give temperature profile for a plane Sai Krishna Fluent UDF and Scheme Programming 1 June 1, 2018 10:05
UDF for output temperature mariam.sara Fluent UDF and Scheme Programming 9 August 19, 2017 08:22
UDF for Back-flow Temperature G340 Fluent UDF and Scheme Programming 3 August 21, 2013 04:56
Inlet won't apply UDF and has temperature at 0K! tccruise Fluent UDF and Scheme Programming 2 September 14, 2012 06:08


All times are GMT -4. The time now is 16:48.